Skip to contentSkip to conversation

scsi-disk: Use (unsigned long) typecasts when using "%lu" format string

PATCH Applied Thomas Huth 3 participants 5 messages Jun 13, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi-disk: Use (unsigned long) typecasts when using "%lu" format string

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

---
 hw/scsi/scsi-disk.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
hw/scsi/scsi-disk.c +4 -4
index 1881969..36f8a85 100644
@@ -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],
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 32 lines · Thomas Huth

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

---
 hw/scsi/scsi-disk.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
hw/scsi/scsi-disk.c +3 -3
index 1881969..36f8a85 100644
@@ -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:

hw/scsi/scsi-disk.c static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf) · line 2086

Quoted 8 lines
hw/scsi/scsi-disk.c +1 -1
@@ -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

#2 lore raw
In reply to Thomas Huth
Quoted 14 lines · Thomas Huth

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

---
 hw/scsi/scsi-disk.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
hw/scsi/scsi-disk.c +0 -0
index 1881969..36f8a85 100644

hw/scsi/scsi-disk.c static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf) · line 2063

Quoted 5 lines
hw/scsi/scsi-disk.c +1 -1
@@ -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)?

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#3 lore raw
Quoted 10 lines · Eric Blake
Quoted 9 lines · Thomas Huth

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

---
 hw/scsi/scsi-disk.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
Quoted 13 lines

hw/scsi/scsi-disk.c static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf) · line 2063

Quoted 10 lines
hw/scsi/scsi-disk.c +1 -1
index 1881969..36f8a85 100644
@@ -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

#4 lore raw
Quoted 25 lines · Thomas Huth
Quoted 10 lines · Eric Blake
Quoted 9 lines · Thomas Huth

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

---
 hw/scsi/scsi-disk.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
Quoted 13 lines

hw/scsi/scsi-disk.c static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf) · line 2063

Quoted 10 lines
hw/scsi/scsi-disk.c +1 -1
index 1881969..36f8a85 100644
@@ -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)?

Quoted 2 lines

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.

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