[PATCH 3/7] Use VIR_ALLOC_VAR instead of VIR_ALLOC_N for creating virObject

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>

The current way virObject instances are allocated using
VIR_ALLOC_N causes alignment warnings

util/virobject.c: In function 'virObjectNew':
util/virobject.c:195:11: error: cast increases required alignment of target type [-Werror=cast-align]

Changing to use VIR_ALLOC_VAR will avoid the need todo
the casts entirely.

Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 src/util/virobject.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/util/virobject.c b/src/util/virobject.c
index 808edc4..93e37e4 100644
--- a/src/util/virobject.c
+++ b/src/util/virobject.c
@@ -186,13 +186,13 @@ bool virClassIsDerivedFrom(virClassPtr klass,
 void *virObjectNew(virClassPtr klass)
 {
     virObjectPtr obj = NULL;
-    char *somebytes;
 
-    if (VIR_ALLOC_N(somebytes, klass->objectSize) < 0) {
+    if (VIR_ALLOC_VAR(obj,
+                      char,
+                      klass->objectSize - sizeof(virObject)) < 0) {
         virReportOOMError();
         return NULL;
     }
-    obj = (virObjectPtr)somebytes;
 
     obj->magic = klass->magic;
     obj->klass = klass;
-- 
1.8.1.4

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




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]