[Qemu-devel] [PATCH v3 09/25] vhost-user: Express sizeof with size_t

Philippe Mathieu-Daudé posted 25 patches 6 years, 8 months ago
Maintainers: Anthony Perard <anthony.perard@citrix.com>, Li Zhijian <lizhijian@cn.fujitsu.com>, Jason Wang <jasowang@redhat.com>, Cornelia Huck <cohuck@redhat.com>, Amit Shah <amit@kernel.org>, "Michael S. Tsirkin" <mst@redhat.com>, Paul Durrant <paul.durrant@citrix.com>, Halil Pasic <pasic@linux.ibm.com>, Christian Borntraeger <borntraeger@de.ibm.com>, David Gibson <david@gibson.dropbear.id.au>, Zhang Chen <zhangckid@gmail.com>, Corey Minyard <minyard@acm.org>, Gerd Hoffmann <kraxel@redhat.com>, Stefano Stabellini <sstabellini@kernel.org>, Paolo Bonzini <pbonzini@redhat.com>, Stefan Berger <stefanb@linux.ibm.com>, Samuel Thibault <samuel.thibault@ens-lyon.org>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
[Qemu-devel] [PATCH v3 09/25] vhost-user: Express sizeof with size_t
Posted by Philippe Mathieu-Daudé 6 years, 8 months ago
VHOST_USER_HDR_SIZE uses offsetof(), thus is an expression of type
size_t. Update the format string accordingly.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 hw/virtio/vhost-user.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index 564a31d12c..2eb7143d3d 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -215,11 +215,12 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)
     struct vhost_user *u = dev->opaque;
     CharBackend *chr = u->user->chr;
     uint8_t *p = (uint8_t *) msg;
-    int r, size = VHOST_USER_HDR_SIZE;
+    int r;
+    size_t size = VHOST_USER_HDR_SIZE;
 
     r = qemu_chr_fe_read_all(chr, p, size);
     if (r != size) {
-        error_report("Failed to read msg header. Read %d instead of %d."
+        error_report("Failed to read msg header. Read %d instead of %zu."
                      " Original request %d.", r, size, msg->hdr.request);
         goto fail;
     }
@@ -235,7 +236,7 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)
     /* validate message size is sane */
     if (msg->hdr.size > VHOST_USER_PAYLOAD_SIZE) {
         error_report("Failed to read msg header."
-                " Size %d exceeds the maximum %zu.", msg->hdr.size,
+                " Size %u exceeds the maximum %zu.", msg->hdr.size,
                 VHOST_USER_PAYLOAD_SIZE);
         goto fail;
     }
@@ -246,7 +247,7 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)
         r = qemu_chr_fe_read_all(chr, p, size);
         if (r != size) {
             error_report("Failed to read msg payload."
-                         " Read %d instead of %d.", r, msg->hdr.size);
+                         " Read %d instead of %u.", r, msg->hdr.size);
             goto fail;
         }
     }
@@ -300,7 +301,8 @@ static int vhost_user_write(struct vhost_dev *dev, VhostUserMsg *msg,
 {
     struct vhost_user *u = dev->opaque;
     CharBackend *chr = u->user->chr;
-    int ret, size = VHOST_USER_HDR_SIZE + msg->hdr.size;
+    int ret;
+    size_t size = VHOST_USER_HDR_SIZE + msg->hdr.size;
 
     /*
      * For non-vring specific requests, like VHOST_USER_SET_MEM_TABLE,
@@ -320,7 +322,7 @@ static int vhost_user_write(struct vhost_dev *dev, VhostUserMsg *msg,
     ret = qemu_chr_fe_write_all(chr, (const uint8_t *) msg, size);
     if (ret != size) {
         error_report("Failed to write msg."
-                     " Wrote %d instead of %d.", ret, size);
+                     " Wrote %d instead of %zu.", ret, size);
         return -1;
     }
 
-- 
2.20.1


Re: [Qemu-devel] [PATCH v3 09/25] vhost-user: Express sizeof with size_t
Posted by Marc-André Lureau 6 years, 8 months ago
On Wed, Feb 20, 2019 at 2:05 AM Philippe Mathieu-Daudé
<philmd@redhat.com> wrote:
>
> VHOST_USER_HDR_SIZE uses offsetof(), thus is an expression of type
> size_t. Update the format string accordingly.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

> ---
>  hw/virtio/vhost-user.c | 14 ++++++++------
>  1 file changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
> index 564a31d12c..2eb7143d3d 100644
> --- a/hw/virtio/vhost-user.c
> +++ b/hw/virtio/vhost-user.c
> @@ -215,11 +215,12 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)
>      struct vhost_user *u = dev->opaque;
>      CharBackend *chr = u->user->chr;
>      uint8_t *p = (uint8_t *) msg;
> -    int r, size = VHOST_USER_HDR_SIZE;
> +    int r;
> +    size_t size = VHOST_USER_HDR_SIZE;
>
>      r = qemu_chr_fe_read_all(chr, p, size);
>      if (r != size) {
> -        error_report("Failed to read msg header. Read %d instead of %d."
> +        error_report("Failed to read msg header. Read %d instead of %zu."
>                       " Original request %d.", r, size, msg->hdr.request);
>          goto fail;
>      }
> @@ -235,7 +236,7 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)
>      /* validate message size is sane */
>      if (msg->hdr.size > VHOST_USER_PAYLOAD_SIZE) {
>          error_report("Failed to read msg header."
> -                " Size %d exceeds the maximum %zu.", msg->hdr.size,
> +                " Size %u exceeds the maximum %zu.", msg->hdr.size,
>                  VHOST_USER_PAYLOAD_SIZE);
>          goto fail;
>      }
> @@ -246,7 +247,7 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)
>          r = qemu_chr_fe_read_all(chr, p, size);
>          if (r != size) {
>              error_report("Failed to read msg payload."
> -                         " Read %d instead of %d.", r, msg->hdr.size);
> +                         " Read %d instead of %u.", r, msg->hdr.size);
>              goto fail;
>          }
>      }
> @@ -300,7 +301,8 @@ static int vhost_user_write(struct vhost_dev *dev, VhostUserMsg *msg,
>  {
>      struct vhost_user *u = dev->opaque;
>      CharBackend *chr = u->user->chr;
> -    int ret, size = VHOST_USER_HDR_SIZE + msg->hdr.size;
> +    int ret;
> +    size_t size = VHOST_USER_HDR_SIZE + msg->hdr.size;
>
>      /*
>       * For non-vring specific requests, like VHOST_USER_SET_MEM_TABLE,
> @@ -320,7 +322,7 @@ static int vhost_user_write(struct vhost_dev *dev, VhostUserMsg *msg,
>      ret = qemu_chr_fe_write_all(chr, (const uint8_t *) msg, size);
>      if (ret != size) {
>          error_report("Failed to write msg."
> -                     " Wrote %d instead of %d.", ret, size);
> +                     " Wrote %d instead of %zu.", ret, size);
>          return -1;
>      }
>
> --
> 2.20.1
>