[Libguestfs] [PATCH 2/2] Cast return value of be64toh to uint64_t before printing.

Richard W.M. Jones rjones at redhat.com
Thu Dec 6 13:32:55 UTC 2012


From: "Richard W.M. Jones" <rjones at redhat.com>

With glibc 2.16-24.fc18, be64toh is a macro around __bswap_64 which is
defined as:

  unsigned long long int __bswap_64 (unsigned long long int __bsx);

Unfortunately on 64 bit platforms, unsigned long long int cannot be
printed using the expansion of PRIu64 ("%lu") resulting in about a
dozen errors such as:

  ldm.c:1129:5: error: format '%lu' expects argument of type 'long unsigned int', but argument 11 has type 'long long unsigned int' [-Werror=format]

This commit corrects the problem by casting the result to uint64_t,
although I'm fairly sure that this is really a bug in glibc.
---
 src/ldm.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/src/ldm.c b/src/ldm.c
index d528a1a..7335982 100644
--- a/src/ldm.c
+++ b/src/ldm.c
@@ -1090,18 +1090,18 @@ _find_vmdb(const void * const config, const gchar * const path,
             "    Size: %" PRIu64 "\n"
             "    Flags2: %016" PRIo64,
             path,
-            be64toh(tocblock->seq1),
-            be64toh(tocblock->seq2),
+            (uint64_t) be64toh(tocblock->seq1),
+            (uint64_t) be64toh(tocblock->seq2),
             tocblock->bitmap[0].name,
             be16toh(tocblock->bitmap[0].flags1),
-            be64toh(tocblock->bitmap[0].start),
-            be64toh(tocblock->bitmap[0].size),
-            be64toh(tocblock->bitmap[0].flags2),
+            (uint64_t) be64toh(tocblock->bitmap[0].start),
+            (uint64_t) be64toh(tocblock->bitmap[0].size),
+            (uint64_t) be64toh(tocblock->bitmap[0].flags2),
             tocblock->bitmap[1].name,
             be16toh(tocblock->bitmap[1].flags1),
-            be64toh(tocblock->bitmap[1].start),
-            be64toh(tocblock->bitmap[1].size),
-            be64toh(tocblock->bitmap[1].flags2));
+            (uint64_t) be64toh(tocblock->bitmap[1].start),
+            (uint64_t) be64toh(tocblock->bitmap[1].size),
+            (uint64_t) be64toh(tocblock->bitmap[1].flags2));
 
     /* Find the start of the DB */
     *vmdb = NULL;
@@ -1150,8 +1150,8 @@ _find_vmdb(const void * const config, const gchar * const path,
             be16toh((*vmdb)->version_major),
             be16toh((*vmdb)->version_minor),
             (*vmdb)->disk_group_guid,
-            be64toh((*vmdb)->committed_seq),
-            be64toh((*vmdb)->pending_seq),
+            (uint64_t) be64toh((*vmdb)->committed_seq),
+            (uint64_t) be64toh((*vmdb)->pending_seq),
             be32toh((*vmdb)->n_committed_vblks_vol),
             be32toh((*vmdb)->n_committed_vblks_comp),
             be32toh((*vmdb)->n_committed_vblks_part),
@@ -1276,10 +1276,10 @@ _read_privhead_off(const int fd, const gchar * const path,
             be16toh(privhead->version_minor),
             privhead->disk_guid,
             privhead->disk_group_guid,
-            be64toh(privhead->logical_disk_start),
-            be64toh(privhead->logical_disk_size),
-            be64toh(privhead->ldm_config_start),
-            be64toh(privhead->ldm_config_size));
+            (uint64_t) be64toh(privhead->logical_disk_start),
+            (uint64_t) be64toh(privhead->logical_disk_size),
+            (uint64_t) be64toh(privhead->ldm_config_start),
+            (uint64_t) be64toh(privhead->ldm_config_size));
 
     return TRUE;
 }
-- 
1.8.0.1




More information about the Libguestfs mailing list