Skip to contentSkip to conversation

fix format string warnings in block-qcow2.c

PATCH Applied Christoph Hellwig 2 participants 2 messages Mar 28, 2009 – Mar 29, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix format string warnings in block-qcow2.c

Recent patches added two compiler warnings about the format string usage in qcow_read_extensions. One is printing a uint64_t using %lu which is incorrect on many platforms as it can be a unsigned long long, the second one is printing the result of sizeof as %lu, but it is a size_t so it needs to be printed using %zu.

block-qcow2.c +3 -3
Index: qemu/block-qcow2.c
===================================================================
@@ -223,8 +223,8 @@ static int qcow_read_extensions(BlockDri
 #endif
 
         if (bdrv_pread(s->hd, offset, &ext, sizeof(ext)) != sizeof(ext)) {
-            fprintf(stderr, "qcow_handle_extension: ERROR: pread fail from offset %lu\n",
-                    offset);
+            fprintf(stderr, "qcow_handle_extension: ERROR: pread fail from offset %llu\n",
+                    (unsigned long long)offset);
             return 1;
         }
         be32_to_cpus(&ext.magic);
@@ -240,7 +240,7 @@ static int qcow_read_extensions(BlockDri
         case QCOW_EXT_MAGIC_BACKING_FORMAT:
             if (ext.len >= sizeof(bs->backing_format)) {
                 fprintf(stderr, "ERROR: ext_backing_format: len=%u too large"
-                        " (>=%lu)\n",
+                        " (>=%zu)\n",
                         ext.len, sizeof(bs->backing_format));
                 return 2;
             }
#1 lore raw
Quoted 9 lines · Christoph Hellwig

Recent patches added two compiler warnings about the format string usage in qcow_read_extensions. One is printing a uint64_t using %lu which is incorrect on many platforms as it can be a unsigned long long, the second one is printing the result of sizeof as %lu, but it is a size_t so it needs to be printed using %zu.

Applied. Thanks.

Regards,

Anthony Liguori

Quoted 28 lines

Index: qemu/block-qcow2.c
===================================================================

block-qcow2.c +3 -3
@@ -223,8 +223,8 @@ static int qcow_read_extensions(BlockDri
 #endif
 
         if (bdrv_pread(s->hd, offset, &ext, sizeof(ext)) != sizeof(ext)) {
-            fprintf(stderr, "qcow_handle_extension: ERROR: pread fail from offset %lu\n",
-                    offset);
+            fprintf(stderr, "qcow_handle_extension: ERROR: pread fail from offset %llu\n",
+                    (unsigned long long)offset);
             return 1;
         }
         be32_to_cpus(&ext.magic);
@@ -240,7 +240,7 @@ static int qcow_read_extensions(BlockDri
         case QCOW_EXT_MAGIC_BACKING_FORMAT:
             if (ext.len >= sizeof(bs->backing_format)) {
                 fprintf(stderr, "ERROR: ext_backing_format: len=%u too large"
-                        " (>=%lu)\n",
+                        " (>=%zu)\n",
                         ext.len, sizeof(bs->backing_format));
                 return 2;
             }