]> xenbits.xensource.com Git - libvirt.git/commitdiff
build: avoid type-punning compiler warning
authorEric Blake <eblake@redhat.com>
Tue, 26 Jul 2011 22:21:10 +0000 (16:21 -0600)
committerEric Blake <eblake@redhat.com>
Thu, 28 Jul 2011 14:16:07 +0000 (08:16 -0600)
On RHEL 5, with gcc 4.1.2:

rpc/virnetsaslcontext.c: In function 'virNetSASLSessionUpdateBufSize':
rpc/virnetsaslcontext.c:396: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

* src/rpc/virnetsaslcontext.c (virNetSASLSessionUpdateBufSize):
Use a union to work around gcc warning.

src/rpc/virnetsaslcontext.c

index 71796b9edbb50eceb17c1aa09d8ac1d142e07c55..a0752dd08dea7480ba52a4f51b6827743023285c 100644 (file)
@@ -390,10 +390,13 @@ cleanup:
 
 static int virNetSASLSessionUpdateBufSize(virNetSASLSessionPtr sasl)
 {
-    unsigned *maxbufsize;
+    union {
+        unsigned *maxbufsize;
+        const void *ptr;
+    } u;
     int err;
 
-    err = sasl_getprop(sasl->conn, SASL_MAXOUTBUF, (const void **)&maxbufsize);
+    err = sasl_getprop(sasl->conn, SASL_MAXOUTBUF, &u.ptr);
     if (err != SASL_OK) {
         virNetError(VIR_ERR_INTERNAL_ERROR,
                     _("cannot get security props %d (%s)"),
@@ -402,8 +405,8 @@ static int virNetSASLSessionUpdateBufSize(virNetSASLSessionPtr sasl)
     }
 
     VIR_DEBUG("Negotiated bufsize is %u vs requested size %zu",
-              *maxbufsize, sasl->maxbufsize);
-    sasl->maxbufsize = *maxbufsize;
+              *u.maxbufsize, sasl->maxbufsize);
+    sasl->maxbufsize = *u.maxbufsize;
     return 0;
 }