diff mbox series

xen: Fix format string

Message ID 20190116120041.17095-1-philmd@redhat.com
State New
Headers show
Series xen: Fix format string | expand

Commit Message

Philippe Mathieu-Daudé Jan. 16, 2019, noon UTC
Trivial format string fix to solve:

  hw/block/xen-block.c: In function 'xen_block_realize':
  hw/block/xen-block.c:218:53: error: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'int64_t {aka long long int}' [-Werror=format=]
      xen_device_backend_printf(xendev, "sectors", "%lu",
                                                      ^
                                blk_getlength(conf->blk) /
                                conf->logical_block_size);

blk_getlength() returns an int64_t.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 hw/block/xen-block.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Paul Durrant Jan. 16, 2019, 12:03 p.m. UTC | #1
> -----Original Message-----
> From: Philippe Mathieu-Daudé [mailto:philmd@redhat.com]
> Sent: 16 January 2019 12:01
> To: qemu-devel@nongnu.org
> Cc: Paul Durrant <Paul.Durrant@citrix.com>; Anthony Perard
> <anthony.perard@citrix.com>; Max Reitz <mreitz@redhat.com>; qemu-
> block@nongnu.org; Stefano Stabellini <sstabellini@kernel.org>; xen-
> devel@lists.xenproject.org; Kevin Wolf <kwolf@redhat.com>; Philippe
> Mathieu-Daudé <philmd@redhat.com>
> Subject: [PATCH] xen: Fix format string
> 
> Trivial format string fix to solve:
> 
>   hw/block/xen-block.c: In function 'xen_block_realize':
>   hw/block/xen-block.c:218:53: error: format '%lu' expects argument of
> type 'long unsigned int', but argument 4 has type 'int64_t {aka long long
> int}' [-Werror=format=]
>       xen_device_backend_printf(xendev, "sectors", "%lu",
>                                                       ^
>                                 blk_getlength(conf->blk) /
>                                 conf->logical_block_size);
> 
> blk_getlength() returns an int64_t.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Reviewed-by: Paul Durrant <paul.durrant@citrix.com>

> ---
>  hw/block/xen-block.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/block/xen-block.c b/hw/block/xen-block.c
> index be28b63442..3cf215b730 100644
> --- a/hw/block/xen-block.c
> +++ b/hw/block/xen-block.c
> @@ -215,7 +215,7 @@ static void xen_block_realize(XenDevice *xendev, Error
> **errp)
> 
>      xen_device_backend_printf(xendev, "sector-size", "%u",
>                                conf->logical_block_size);
> -    xen_device_backend_printf(xendev, "sectors", "%lu",
> +    xen_device_backend_printf(xendev, "sectors", "%lld",
>                                blk_getlength(conf->blk) /
>                                conf->logical_block_size);
> 
> --
> 2.17.2
Paul Durrant Jan. 16, 2019, 12:18 p.m. UTC | #2
> -----Original Message-----
> From: Xen-devel [mailto:xen-devel-bounces@lists.xenproject.org] On Behalf
> Of Paul Durrant
> Sent: 16 January 2019 12:04
> To: 'Philippe Mathieu-Daudé' <philmd@redhat.com>; qemu-devel@nongnu.org
> Cc: Kevin Wolf <kwolf@redhat.com>; Stefano Stabellini
> <sstabellini@kernel.org>; qemu-block@nongnu.org; Max Reitz
> <mreitz@redhat.com>; Anthony Perard <anthony.perard@citrix.com>; xen-
> devel@lists.xenproject.org
> Subject: Re: [Xen-devel] [PATCH] xen: Fix format string
> 
> > -----Original Message-----
> > From: Philippe Mathieu-Daudé [mailto:philmd@redhat.com]
> > Sent: 16 January 2019 12:01
> > To: qemu-devel@nongnu.org
> > Cc: Paul Durrant <Paul.Durrant@citrix.com>; Anthony Perard
> > <anthony.perard@citrix.com>; Max Reitz <mreitz@redhat.com>; qemu-
> > block@nongnu.org; Stefano Stabellini <sstabellini@kernel.org>; xen-
> > devel@lists.xenproject.org; Kevin Wolf <kwolf@redhat.com>; Philippe
> > Mathieu-Daudé <philmd@redhat.com>
> > Subject: [PATCH] xen: Fix format string
> >
> > Trivial format string fix to solve:
> >
> >   hw/block/xen-block.c: In function 'xen_block_realize':
> >   hw/block/xen-block.c:218:53: error: format '%lu' expects argument of
> > type 'long unsigned int', but argument 4 has type 'int64_t {aka long
> long
> > int}' [-Werror=format=]
> >       xen_device_backend_printf(xendev, "sectors", "%lu",
> >                                                       ^
> >                                 blk_getlength(conf->blk) /
> >                                 conf->logical_block_size);
> >
> > blk_getlength() returns an int64_t.
> >
> > Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> 
> Reviewed-by: Paul Durrant <paul.durrant@citrix.com>

Actually, the alternative patch from Alex is better as it will work in the case where longs are not 64-bit.

  Paul

> 
> > ---
> >  hw/block/xen-block.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/hw/block/xen-block.c b/hw/block/xen-block.c
> > index be28b63442..3cf215b730 100644
> > --- a/hw/block/xen-block.c
> > +++ b/hw/block/xen-block.c
> > @@ -215,7 +215,7 @@ static void xen_block_realize(XenDevice *xendev,
> Error
> > **errp)
> >
> >      xen_device_backend_printf(xendev, "sector-size", "%u",
> >                                conf->logical_block_size);
> > -    xen_device_backend_printf(xendev, "sectors", "%lu",
> > +    xen_device_backend_printf(xendev, "sectors", "%lld",
> >                                blk_getlength(conf->blk) /
> >                                conf->logical_block_size);
> >
> > --
> > 2.17.2
> 
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xenproject.org
> https://lists.xenproject.org/mailman/listinfo/xen-devel
diff mbox series

Patch

diff --git a/hw/block/xen-block.c b/hw/block/xen-block.c
index be28b63442..3cf215b730 100644
--- a/hw/block/xen-block.c
+++ b/hw/block/xen-block.c
@@ -215,7 +215,7 @@  static void xen_block_realize(XenDevice *xendev, Error **errp)
 
     xen_device_backend_printf(xendev, "sector-size", "%u",
                               conf->logical_block_size);
-    xen_device_backend_printf(xendev, "sectors", "%lu",
+    xen_device_backend_printf(xendev, "sectors", "%lld",
                               blk_getlength(conf->blk) /
                               conf->logical_block_size);