[libvirt] [PATCH v3 4/5] virobject: Check if @parent is the first member in class

Michal Privoznik posted 5 patches 7 years ago
[libvirt] [PATCH v3 4/5] virobject: Check if @parent is the first member in class
Posted by Michal Privoznik 7 years ago
Our virObject code relies heavily on the fact that the first
member of the class struct is type of virObject (or some
derivation of if). Let's check for that.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/util/virobject.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/util/virobject.h b/src/util/virobject.h
index ed1a117b09..77ebad1e8b 100644
--- a/src/util/virobject.h
+++ b/src/util/virobject.h
@@ -76,7 +76,8 @@ virClassPtr virClassForObjectRWLockable(void);
 # endif
 
 # define VIR_CLASS_NEW(name, prnt) \
-    (name##Class = virClassNew(prnt, #name, sizeof(name), name##Dispose))
+    verify_expr(offsetof(name, parent) == 0, \
+      (name##Class = virClassNew(prnt, #name, sizeof(name), name##Dispose)))
 
 virClassPtr
 virClassNew(virClassPtr parent,
-- 
2.16.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v3 4/5] virobject: Check if @parent is the first member in class
Posted by Daniel P. Berrangé 7 years ago
On Tue, Apr 17, 2018 at 06:01:05PM +0200, Michal Privoznik wrote:
> Our virObject code relies heavily on the fact that the first
> member of the class struct is type of virObject (or some
> derivation of if). Let's check for that.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/util/virobject.h | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list