]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virobject: Check if @parent is the first member in class
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 17 Apr 2018 15:52:03 +0000 (17:52 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 18 Apr 2018 08:04:55 +0000 (10:04 +0200)
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>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
src/util/virobject.h

index ed1a117b09b89797321473f8ced6c04fabd75a79..77ebad1e8b783ac6b24f1cdb0b808bdfd5a1d88e 100644 (file)
@@ -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,