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

Michal Privoznik mprivozn at redhat.com
Tue Apr 17 08:20:52 UTC 2018


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 at redhat.com>
---
 src/util/virobject.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/util/virobject.h b/src/util/virobject.h
index 128d3ba2d2..e174c17eb8 100644
--- a/src/util/virobject.h
+++ b/src/util/virobject.h
@@ -76,10 +76,12 @@ virClassPtr virClassForObjectRWLockable(void);
 # endif
 
 # define VIR_CLASS_NEW(prnt, name) \
+    verify(offsetof(name, parent) == 0); \
     if (!(name##Class = virClassNew(prnt, #name, sizeof(name), name##Dispose))) \
         return -1;
 
 # define VIR_CLASS_NEW_GOTO(prnt, name, label) \
+    verify(offsetof(name, parent) == 0); \
     if (!(name##Class = virClassNew(prnt, #name, sizeof(name), name##Dispose))) \
         goto label;
 
-- 
2.16.1




More information about the libvir-list mailing list