[virt-tools-list] [vhostmd PATCH 1/3] Fix compiler warnings

Jim Fehlig jfehlig at suse.com
Wed Dec 18 20:29:32 UTC 2019


On 11/25/19 11:26 AM, Michael Trapp wrote:
> From: d032747 <michael.trapp at sap.com>

You'll need to fix this or remove it. In addition, please provide an example of 
the compiler warning in the commit message. Without this patch I'm not seeing 
any warnings with '-Wall -Werror'.

> 
> ---
>   vhostmd/virtio.c | 24 +++++++++++-------------
>   1 file changed, 11 insertions(+), 13 deletions(-)
> 
> diff --git a/vhostmd/virtio.c b/vhostmd/virtio.c
> index f227b45..857123d 100644
> --- a/vhostmd/virtio.c
> +++ b/vhostmd/virtio.c
> @@ -69,7 +69,7 @@ static time_t exp_period = 0;
>   
>   static const char *channel_path = "/var/lib/libvirt/qemu/channel/target";
>   static const char *channel_name = "org.github.vhostmd.1";
> -static int channel_max = 0;
> +static size_t channel_max = 0;
>   static volatile int channel_count = 0;
>   static volatile int connection_count = 0;
>   
> @@ -216,7 +216,7 @@ static int vio_channel_open(channel_t * c)
>   
>       connection_count++;
>   
> -    vu_log(VHOSTMD_INFO, "Opened channel '%d %s' (%d/%d/%d)",
> +    vu_log(VHOSTMD_INFO, "Opened channel '%d %s' (%d/%d/%lu)",
>              c->id, c->name, connection_count, channel_count, channel_max);
>   
>       return 0;
> @@ -243,7 +243,7 @@ static void vio_channel_close(channel_t * c)
>       if (c->fd != FREE)
>           connection_count--;
>   
> -    vu_log(VHOSTMD_INFO, "Closed channel '%d %s' (%d/%d/%d)",
> +    vu_log(VHOSTMD_INFO, "Closed channel '%d %s' (%d/%d/%lu)",
>              c->id, c->name, connection_count, channel_count,  channel_max);
>       vio_channel_free(c);
>   
> @@ -322,7 +322,7 @@ error:
>    */
>   static void vio_expire(void)
>   {
> -    int i;
> +    unsigned i;
>       time_t ts = time(NULL) - exp_period;
>   
>       for (i = 1; i <= channel_max; i++) {
> @@ -333,7 +333,7 @@ static void vio_expire(void)
>               c->update_ts < ts) {
>   
>   #ifdef ENABLE_DEBUG
> -            vu_log(VHOSTMD_DEBUG, "Expire channel '%s' (%d/%d/%d)",
> +            vu_log(VHOSTMD_DEBUG, "Expire channel '%s' (%d/%d/%u)",

With the patch I see a warning here

virtio.c:336:64: error: format ‘%u’ expects argument of type ‘unsigned int’, but 
argument 6 has type ‘size_t {aka long unsigned int}’ [-Werror=format=]

>                      c->name, connection_count, channel_count, channel_max);
>   #endif
>               vio_channel_close(c);
> @@ -364,7 +364,7 @@ static channel_t *vio_channel_find(int id, const char * name, int insert)
>           int i;
>   #endif
>           vu_log(VHOSTMD_ERR,
> -               "Could not add channel '%d %s' - too many VMs (%d/%d/%d)",
> +               "Could not add channel '%d %s' - too many VMs (%d/%d/%lu)",
>                  id, name, connection_count, channel_count, channel_max);
>   
>   #ifdef ENABLE_DEBUG
> @@ -399,7 +399,7 @@ static channel_t *vio_channel_find(int id, const char * name, int insert)
>           vu_buffer_create(&c->response, DEFAULT_VU_BUFFER_SIZE))
>           goto error;
>   
> -    vu_log(VHOSTMD_INFO, "Added channel '%d %s' (%d/%d/%d)",
> +    vu_log(VHOSTMD_INFO, "Added channel '%d %s' (%d/%d/%lu)",
>              c->id, c->name, connection_count, channel_count, channel_max);
>   
>       return c;
> @@ -583,8 +583,7 @@ int virtio_init(int _max_channel, int _expiration_period)
>           channel_count = 0;
>           connection_count = 0;
>   
> -        channel = (channel_t *) calloc((size_t) (channel_max + 1),
> -                                       sizeof(channel_t));
> +        channel = (channel_t *) calloc(channel_max + 1, sizeof(channel_t));
>           if (channel == NULL)
>               goto error;
>   
> @@ -595,7 +594,7 @@ int virtio_init(int _max_channel, int _expiration_period)
>               channel[i].fd = -1;
>           }
>   
> -        id_map = (id_map_t *) calloc((size_t) channel_max, sizeof(id_map_t));
> +        id_map = (id_map_t *) calloc(channel_max, sizeof(id_map_t));
>           if (id_map == NULL)
>               goto error;
>   
> @@ -606,8 +605,7 @@ int virtio_init(int _max_channel, int _expiration_period)
>   
>           if (epoll_fd == -1) {
>   
> -            epoll_events = calloc((size_t) (channel_max + 1),
> -                                  sizeof(struct epoll_event));
> +            epoll_events = calloc(channel_max + 1, sizeof(struct epoll_event));
>               if (epoll_events == NULL)
>                   goto error;
>   
> @@ -618,7 +616,7 @@ int virtio_init(int _max_channel, int _expiration_period)
>   
>           virtio_status = VIRTIO_ACTIVE;
>           vu_log(VHOSTMD_INFO,
> -               "Activating virtio, using max_channels %d, expiration_time %ld",
> +               "Activating virtio, using max_channels %lu, expiration_time %ld",
>                  channel_max, exp_period);
>       }
>   
> 

I'm also seeing these new warnings with the patch

virtio.c: In function ‘vio_channel_find’:
virtio.c:362:23: error: comparison between signed and unsigned integer 
expressions [-Werror=sign-compare]
      if (channel_count >= channel_max) {
                        ^~
virtio.c:372:23: error: comparison between signed and unsigned integer 
expressions [-Werror=sign-compare]
          for (i = 1; i <= channel_max; i++) {
                        ^~
virtio.c: In function ‘virtio_init’:
virtio.c:592:23: error: comparison between signed and unsigned integer 
expressions [-Werror=sign-compare]
          for (i = 1; i <= channel_max; i++) {
                        ^~
virtio.c:601:23: error: comparison between signed and unsigned integer 
expressions [-Werror=sign-compare]
          for (i = 0; i < channel_max; i++) {
                        ^
virtio.c: In function ‘virtio_cleanup’:
virtio.c:647:27: error: comparison between signed and unsigned integer 
expressions [-Werror=sign-compare]
              for (i = 0; i <= channel_max; i++)
                            ^~

Using gcc 7.4.1.

Regards,
Jim




More information about the virt-tools-list mailing list