]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Make all bitfields unsigned ints to avoid unexpected values in casts
authorDaniel P. Berrange <berrange@redhat.com>
Tue, 19 Jan 2010 12:07:32 +0000 (12:07 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Wed, 20 Jan 2010 16:33:02 +0000 (16:33 +0000)
The 'int virInterfaceIsActive()' method was directly returning the
value of the 'int active:1' bitfield in virIntefaceDefPtr. A bitfield
with a signed integer, will hold the values 0 and -1, not 0 and +1
as might be expected. This meant that virInterfaceIsActive() was
always returning -1 when the interface was active, not +1 & thus all
callers thought an error had occurred. To protect against this kind
of mistake again, change all bitfields to be unsigned ints

* daemon/libvirtd.h, src/conf/domain_conf.h, src/conf/interface_conf.h,
  src/conf/network_conf.h: Change bitfields to unsigned int.

daemon/libvirtd.h
src/conf/domain_conf.h
src/conf/interface_conf.h
src/conf/network_conf.h

index 2f647f3fbb05035229f7f951743928965b1a4bb1..a7591fc4720d16293dcd1db36b1143f335292991 100644 (file)
@@ -175,9 +175,9 @@ struct qemud_client {
 
     int fd;
     int watch;
-    int readonly:1;
-    int closing:1;
-    int domain_events_registered:1;
+    unsigned int readonly :1;
+    unsigned int closing :1;
+    unsigned int domain_events_registered :1;
 
     struct sockaddr_storage addr;
     socklen_t addrlen;
@@ -185,7 +185,7 @@ struct qemud_client {
     int type; /* qemud_sock_type */
     gnutls_session_t tlssession;
     int auth;
-    int handshake : 1; /* If we're in progress for TLS handshake */
+    unsigned int handshake :1; /* If we're in progress for TLS handshake */
 #if HAVE_SASL
     sasl_conn_t *saslconn;
     int saslSSF;
@@ -244,9 +244,9 @@ struct qemud_socket {
 
 struct qemud_worker {
     pthread_t thread;
-    int hasThread :1;
-    int processingCall :1;
-    int quitRequest : 1;
+    unsigned int hasThread :1;
+    unsigned int processingCall :1;
+    unsigned int quitRequest :1;
 
     /* back-pointer to our server */
     struct qemud_server *server;
index 14132736549c074c25d278a72a9aaef451c01db3..7be090d444e0ad67adabf4d18606692f8fc6f10c 100644 (file)
@@ -400,8 +400,8 @@ enum virDomainVideoType {
 typedef struct _virDomainVideoAccelDef virDomainVideoAccelDef;
 typedef virDomainVideoAccelDef *virDomainVideoAccelDefPtr;
 struct _virDomainVideoAccelDef {
-    int support3d : 1;
-    int support2d : 1;
+    unsigned int support3d :1;
+    unsigned int support2d :1;
 };
 
 
@@ -432,7 +432,7 @@ struct _virDomainGraphicsDef {
     union {
         struct {
             int port;
-            int autoport : 1;
+            unsigned int autoport :1;
             char *listenAddr;
             char *keymap;
             char *passwd;
@@ -445,13 +445,13 @@ struct _virDomainGraphicsDef {
         struct {
             int port;
             char *listenAddr;
-            int autoport : 1;
-            int replaceUser : 1;
-            int multiUser : 1;
+            unsigned int autoport :1;
+            unsigned int replaceUser :1;
+            unsigned int multiUser :1;
         } rdp;
         struct {
             char *display;
-            int fullscreen : 1;
+            unsigned int fullscreen :1;
         } desktop;
     } data;
 };
index 889ad9457e19b220b4cc99f37dcb38d3dbe3c09a..8a18a03cd3e9a963e893f7de5ca252dec0fc03f8 100644 (file)
@@ -164,7 +164,7 @@ typedef virInterfaceObj *virInterfaceObjPtr;
 struct _virInterfaceObj {
     virMutex lock;
 
-    int active:1;           /* 1 if interface is active (up) */
+    unsigned int active:1;           /* 1 if interface is active (up) */
     virInterfaceDefPtr def; /* The interface definition */
 };
 
index 0214d1a28374e7547252e57a837d8420df920d5c..9e5065920ec5827bb9cc94fbe07d0e4e126f0936 100644 (file)
@@ -65,7 +65,7 @@ struct _virNetworkDef {
     char *bridge;       /* Name of bridge device */
     char *domain;
     unsigned long delay;   /* Bridge forward delay (ms) */
-    int stp : 1; /* Spanning tree protocol */
+    unsigned int stp :1; /* Spanning tree protocol */
 
     int forwardType;    /* One of virNetworkForwardType constants */
     char *forwardDev;   /* Destination device for forwarding */