qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] scsi-disk: Use (unsigned long) typecasts when using "%lu" format string
@ 2016-06-13  8:10 Thomas Huth
  2016-06-13 10:03 ` Paolo Bonzini
  2016-06-13 15:27 ` Eric Blake
  0 siblings, 2 replies; 5+ messages in thread
From: Thomas Huth @ 2016-06-13  8:10 UTC (permalink / raw)
  To: qemu-devel; +Cc: Paolo Bonzini, qemu-trivial

Some source code analyzers like cppcheck spill out a warning if
the sign of the argument does not match the format string.

Ticket: https://bugs.launchpad.net/qemu/+bug/1589564
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 hw/scsi/scsi-disk.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index 1881969..36f8a85 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -2060,13 +2060,13 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf)
         }
         break;
     case MODE_SELECT:
-        DPRINTF("Mode Select(6) (len %lu)\n", (long)r->req.cmd.xfer);
+        DPRINTF("Mode Select(6) (len %lu)\n", (unsigned long)r->req.cmd.xfer);
         break;
     case MODE_SELECT_10:
-        DPRINTF("Mode Select(10) (len %lu)\n", (long)r->req.cmd.xfer);
+        DPRINTF("Mode Select(10) (len %lu)\n", (unsigned long)r->req.cmd.xfer);
         break;
     case UNMAP:
-        DPRINTF("Unmap (len %lu)\n", (long)r->req.cmd.xfer);
+        DPRINTF("Unmap (len %lu)\n", (unsigned long)r->req.cmd.xfer);
         break;
     case VERIFY_10:
     case VERIFY_12:
@@ -2080,7 +2080,7 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf)
     case WRITE_SAME_16:
         DPRINTF("WRITE SAME %d (len %lu)\n",
                 req->cmd.buf[0] == WRITE_SAME_10 ? 10 : 16,
-                (long)r->req.cmd.xfer);
+                (unsigned long)r->req.cmd.xfer);
         break;
     default:
         DPRINTF("Unknown SCSI command (%2.2x=%s)\n", buf[0],
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] scsi-disk: Use (unsigned long) typecasts when using "%lu" format string
  2016-06-13  8:10 [Qemu-devel] [PATCH] scsi-disk: Use (unsigned long) typecasts when using "%lu" format string Thomas Huth
@ 2016-06-13 10:03 ` Paolo Bonzini
  2016-06-13 15:27 ` Eric Blake
  1 sibling, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2016-06-13 10:03 UTC (permalink / raw)
  To: Thomas Huth, qemu-devel; +Cc: qemu-trivial



On 13/06/2016 10:10, Thomas Huth wrote:
> Some source code analyzers like cppcheck spill out a warning if
> the sign of the argument does not match the format string.
> 
> Ticket: https://bugs.launchpad.net/qemu/+bug/1589564
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>  hw/scsi/scsi-disk.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
> index 1881969..36f8a85 100644
> --- a/hw/scsi/scsi-disk.c
> +++ b/hw/scsi/scsi-disk.c
> @@ -2060,13 +2060,13 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf)
>          }
>          break;
>      case MODE_SELECT:
> -        DPRINTF("Mode Select(6) (len %lu)\n", (long)r->req.cmd.xfer);
> +        DPRINTF("Mode Select(6) (len %lu)\n", (unsigned long)r->req.cmd.xfer);
>          break;
>      case MODE_SELECT_10:
> -        DPRINTF("Mode Select(10) (len %lu)\n", (long)r->req.cmd.xfer);
> +        DPRINTF("Mode Select(10) (len %lu)\n", (unsigned long)r->req.cmd.xfer);
>          break;
>      case UNMAP:
> -        DPRINTF("Unmap (len %lu)\n", (long)r->req.cmd.xfer);
> +        DPRINTF("Unmap (len %lu)\n", (unsigned long)r->req.cmd.xfer);
>          break;
>      case VERIFY_10:
>      case VERIFY_12:
> @@ -2080,7 +2080,7 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf)
>      case WRITE_SAME_16:
>          DPRINTF("WRITE SAME %d (len %lu)\n",
>                  req->cmd.buf[0] == WRITE_SAME_10 ? 10 : 16,
> -                (long)r->req.cmd.xfer);
> +                (unsigned long)r->req.cmd.xfer);
>          break;
>      default:
>          DPRINTF("Unknown SCSI command (%2.2x=%s)\n", buf[0],
> 

Queued, thanks.

Paolo

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] scsi-disk: Use (unsigned long) typecasts when using "%lu" format string
  2016-06-13  8:10 [Qemu-devel] [PATCH] scsi-disk: Use (unsigned long) typecasts when using "%lu" format string Thomas Huth
  2016-06-13 10:03 ` Paolo Bonzini
@ 2016-06-13 15:27 ` Eric Blake
  2016-06-13 16:00   ` Thomas Huth
  1 sibling, 1 reply; 5+ messages in thread
From: Eric Blake @ 2016-06-13 15:27 UTC (permalink / raw)
  To: Thomas Huth, qemu-devel; +Cc: qemu-trivial, Paolo Bonzini

[-- Attachment #1: Type: text/plain, Size: 1096 bytes --]

On 06/13/2016 02:10 AM, Thomas Huth wrote:
> Some source code analyzers like cppcheck spill out a warning if
> the sign of the argument does not match the format string.
> 
> Ticket: https://bugs.launchpad.net/qemu/+bug/1589564
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>  hw/scsi/scsi-disk.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
> index 1881969..36f8a85 100644
> --- a/hw/scsi/scsi-disk.c
> +++ b/hw/scsi/scsi-disk.c
> @@ -2060,13 +2060,13 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf)
>          }
>          break;
>      case MODE_SELECT:
> -        DPRINTF("Mode Select(6) (len %lu)\n", (long)r->req.cmd.xfer);
> +        DPRINTF("Mode Select(6) (len %lu)\n", (unsigned long)r->req.cmd.xfer);

Why do we need a cast in the first place?  r->req.cmd.xfer is size_t, so
why not just "Mode Select(6) (len %zu)\n", r->req.cmd.xfer)?

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] scsi-disk: Use (unsigned long) typecasts when using "%lu" format string
  2016-06-13 15:27 ` Eric Blake
@ 2016-06-13 16:00   ` Thomas Huth
  2016-06-13 16:04     ` Eric Blake
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas Huth @ 2016-06-13 16:00 UTC (permalink / raw)
  To: Eric Blake, qemu-devel; +Cc: qemu-trivial, Paolo Bonzini

[-- Attachment #1: Type: text/plain, Size: 1156 bytes --]

On 13.06.2016 17:27, Eric Blake wrote:
> On 06/13/2016 02:10 AM, Thomas Huth wrote:
>> Some source code analyzers like cppcheck spill out a warning if
>> the sign of the argument does not match the format string.
>>
>> Ticket: https://bugs.launchpad.net/qemu/+bug/1589564
>> Signed-off-by: Thomas Huth <thuth@redhat.com>
>> ---
>>  hw/scsi/scsi-disk.c | 8 ++++----
>>  1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
>> index 1881969..36f8a85 100644
>> --- a/hw/scsi/scsi-disk.c
>> +++ b/hw/scsi/scsi-disk.c
>> @@ -2060,13 +2060,13 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf)
>>          }
>>          break;
>>      case MODE_SELECT:
>> -        DPRINTF("Mode Select(6) (len %lu)\n", (long)r->req.cmd.xfer);
>> +        DPRINTF("Mode Select(6) (len %lu)\n", (unsigned long)r->req.cmd.xfer);
> 
> Why do we need a cast in the first place?  r->req.cmd.xfer is size_t, so
> why not just "Mode Select(6) (len %zu)\n", r->req.cmd.xfer)?

That sounds good, too. Do you want to provide a patch, or shall I do a
v2 of my patch?

 Thomas



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] scsi-disk: Use (unsigned long) typecasts when using "%lu" format string
  2016-06-13 16:00   ` Thomas Huth
@ 2016-06-13 16:04     ` Eric Blake
  0 siblings, 0 replies; 5+ messages in thread
From: Eric Blake @ 2016-06-13 16:04 UTC (permalink / raw)
  To: Thomas Huth, qemu-devel; +Cc: qemu-trivial, Paolo Bonzini

[-- Attachment #1: Type: text/plain, Size: 1372 bytes --]

On 06/13/2016 10:00 AM, Thomas Huth wrote:
> On 13.06.2016 17:27, Eric Blake wrote:
>> On 06/13/2016 02:10 AM, Thomas Huth wrote:
>>> Some source code analyzers like cppcheck spill out a warning if
>>> the sign of the argument does not match the format string.
>>>
>>> Ticket: https://bugs.launchpad.net/qemu/+bug/1589564
>>> Signed-off-by: Thomas Huth <thuth@redhat.com>
>>> ---
>>>  hw/scsi/scsi-disk.c | 8 ++++----
>>>  1 file changed, 4 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
>>> index 1881969..36f8a85 100644
>>> --- a/hw/scsi/scsi-disk.c
>>> +++ b/hw/scsi/scsi-disk.c
>>> @@ -2060,13 +2060,13 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf)
>>>          }
>>>          break;
>>>      case MODE_SELECT:
>>> -        DPRINTF("Mode Select(6) (len %lu)\n", (long)r->req.cmd.xfer);
>>> +        DPRINTF("Mode Select(6) (len %lu)\n", (unsigned long)r->req.cmd.xfer);
>>
>> Why do we need a cast in the first place?  r->req.cmd.xfer is size_t, so
>> why not just "Mode Select(6) (len %zu)\n", r->req.cmd.xfer)?
> 
> That sounds good, too. Do you want to provide a patch, or shall I do a
> v2 of my patch?

Up to Paolo, since he's already queued v1.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-06-13 16:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-13  8:10 [Qemu-devel] [PATCH] scsi-disk: Use (unsigned long) typecasts when using "%lu" format string Thomas Huth
2016-06-13 10:03 ` Paolo Bonzini
2016-06-13 15:27 ` Eric Blake
2016-06-13 16:00   ` Thomas Huth
2016-06-13 16:04     ` Eric Blake

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).