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

[libvirt] [PATCH] build: avoid type-punning compiler warning



On RHEL 5, with gcc 4.1.2:

rpc/virnetsaslcontext.c: In function 'virNetSASLSessionUpdateBufSize':
rpc/virnetsaslcontext.c:396: warning: dereferncing 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 |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/rpc/virnetsaslcontext.c b/src/rpc/virnetsaslcontext.c
index 71796b9..a0752dd 100644
--- a/src/rpc/virnetsaslcontext.c
+++ b/src/rpc/virnetsaslcontext.c
@@ -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;
 }

-- 
1.7.4.4


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