Re: [libvirt] [PATCH] Make all bitfields unsigned ints to avoid unexpected values in casts

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

 



On Tue, Jan 19, 2010 at 12:10:24PM +0000, Daniel P. Berrange wrote:
> 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         |   14 +++++++-------
>  src/conf/domain_conf.h    |   14 +++++++-------
>  src/conf/interface_conf.h |    2 +-
>  src/conf/network_conf.h   |    2 +-
>  4 files changed, 16 insertions(+), 16 deletions(-)
> 
> diff --git a/daemon/libvirtd.h b/daemon/libvirtd.h
> index 2f647f3..a7591fc 100644
> --- a/daemon/libvirtd.h
> +++ b/daemon/libvirtd.h
> @@ -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;
> diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
> index 1413273..7be090d 100644
> --- a/src/conf/domain_conf.h
> +++ b/src/conf/domain_conf.h
> @@ -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;
>  };
> diff --git a/src/conf/interface_conf.h b/src/conf/interface_conf.h
> index 2683eee..5b201d3 100644
> --- a/src/conf/interface_conf.h
> +++ b/src/conf/interface_conf.h
> @@ -170,7 +170,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 */
>  };
>  
> diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
> index 0214d1a..9e50659 100644
> --- a/src/conf/network_conf.h
> +++ b/src/conf/network_conf.h
> @@ -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 */

  ACK, one checking point to keep in mind, good idea !

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel@xxxxxxxxxxxx  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/

--
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]