[Libguestfs] [PATCH] Fix various -Wformat problems.

Richard W.M. Jones rjones at redhat.com
Thu Jul 2 15:06:45 UTC 2015


Updating gnulib has caused -Wformat-signedness to be enabled.  This
has revealed many problems in C format strings.  The fixes here fall
into the following main categories:

 - Using %d with an unsigned parameter.

 - %x and %o expect an unsigned argument.

 - uid_t and gid_t are unsigned on Linux.  The safe way to print these
   is to cast them to uintmax_t and then print then using the %ju
   modifier (see http://stackoverflow.com/a/1401581).

 - Using %d to print an enum.  Since enums may be either char or int,
   I fixed this by casting the enum to int.

 - strtol_error & lzma_ret are both unsigned types.
---
 builder/pxzcat-c.c     | 24 ++++++++++++------------
 cat/filesystems.c      |  2 +-
 cat/ls.c               |  5 +++--
 daemon/ext2.c          |  7 ++++++-
 daemon/file.c          |  2 +-
 daemon/guestfsd.c      |  3 ++-
 daemon/parted.c        |  5 +++--
 daemon/proto.c         | 14 ++++++++------
 daemon/umask.c         |  2 +-
 daemon/zero.c          |  2 +-
 diff/diff.c            |  7 ++++---
 fish/alloc.c           |  2 +-
 fish/rc.c              |  8 ++++----
 generator/bindtests.ml |  2 +-
 generator/daemon.ml    |  4 ++--
 generator/fish.ml      | 17 +++++++++--------
 make-fs/make-fs.c      |  2 +-
 p2v/main.c             |  5 +++--
 src/actions-support.c  | 10 +++++-----
 src/appliance.c        |  6 +++---
 src/fuse.c             | 14 +++++++-------
 src/handle.c           |  2 +-
 src/launch-libvirt.c   |  3 ++-
 src/launch.c           |  2 +-
 src/proto.c            |  2 +-
 test-tool/test-tool.c  |  2 +-
 26 files changed, 84 insertions(+), 70 deletions(-)

diff --git a/builder/pxzcat-c.c b/builder/pxzcat-c.c
index fb1a865..0c4a4be 100644
--- a/builder/pxzcat-c.c
+++ b/builder/pxzcat-c.c
@@ -298,7 +298,7 @@ parse_indexes (value filenamev, int fd)
     /* Does the stream footer look reasonable? */
     r = lzma_stream_footer_decode (&footer_flags, footer);
     if (r != LZMA_OK) {
-      fprintf (stderr, "invalid stream footer - error %d\n", r);
+      fprintf (stderr, "invalid stream footer - error %u\n", r);
       caml_invalid_argument ("invalid stream footer");
     }
 
@@ -317,7 +317,7 @@ parse_indexes (value filenamev, int fd)
     /* Decode the index. */
     r = lzma_index_decoder (&strm, &this_index, UINT64_MAX);
     if (r != LZMA_OK) {
-      fprintf (stderr, "invalid stream index - error %d\n", r);
+      fprintf (stderr, "invalid stream index - error %u\n", r);
       caml_invalid_argument ("invalid stream index");
     }
 
@@ -339,7 +339,7 @@ parse_indexes (value filenamev, int fd)
     } while (r == LZMA_OK);
 
     if (r != LZMA_STREAM_END) {
-      fprintf (stderr, "could not parse index - error %d\n", r);
+      fprintf (stderr, "could not parse index - error %u\n", r);
       caml_invalid_argument ("could not parse index");
     }
 
@@ -356,14 +356,14 @@ parse_indexes (value filenamev, int fd)
 
     r = lzma_stream_header_decode (&header_flags, header);
     if (r != LZMA_OK) {
-      fprintf (stderr, "invalid stream header - error %d\n", r);
+      fprintf (stderr, "invalid stream header - error %u\n", r);
       caml_invalid_argument ("invalid stream header");
     }
 
     /* Header and footer of the stream should be equal. */
     r = lzma_stream_flags_compare (&header_flags, &footer_flags);
     if (r != LZMA_OK) {
-      fprintf (stderr, "header and footer of stream are not equal - error %d\n",
+      fprintf (stderr, "header and footer of stream are not equal - error %u\n",
                r);
       caml_invalid_argument ("header and footer of stream are not equal");
     }
@@ -371,7 +371,7 @@ parse_indexes (value filenamev, int fd)
     /* Store the decoded stream flags in this_index. */
     r = lzma_index_stream_flags (this_index, &footer_flags);
     if (r != LZMA_OK) {
-      fprintf (stderr, "cannot read stream_flags from index - error %d\n", r);
+      fprintf (stderr, "cannot read stream_flags from index - error %u\n", r);
       caml_invalid_argument ("cannot read stream_flags from index");
     }
 
@@ -380,14 +380,14 @@ parse_indexes (value filenamev, int fd)
      */
     r = lzma_index_stream_padding (this_index, stream_padding);
     if (r != LZMA_OK) {
-      fprintf (stderr, "cannot set stream_padding in index - error %d\n", r);
+      fprintf (stderr, "cannot set stream_padding in index - error %u\n", r);
       caml_invalid_argument ("cannot set stream_padding in index");
     }
 
     if (combined_index != NULL) {
       r = lzma_index_cat (this_index, combined_index, NULL);
       if (r != LZMA_OK) {
-        fprintf (stderr, "cannot combine indexes - error %d\n", r);
+        fprintf (stderr, "cannot combine indexes - error %u\n", r);
         caml_invalid_argument ("cannot combine indexes");
       }
     }
@@ -613,7 +613,7 @@ worker_thread (void *vp)
 
     r = lzma_block_header_decode (&block, NULL, header);
     if (r != LZMA_OK) {
-      fprintf (stderr, "%s: invalid block header (error %d)\n",
+      fprintf (stderr, "%s: invalid block header (error %u)\n",
                global->filename, r);
       return &state->status;
     }
@@ -624,7 +624,7 @@ worker_thread (void *vp)
     r = lzma_block_compressed_size (&block, iter.block.unpadded_size);
     if (r != LZMA_OK) {
       fprintf (stderr,
-               "%s: cannot calculate compressed size (error %d)\n",
+               "%s: cannot calculate compressed size (error %u)\n",
                global->filename, r);
       return &state->status;
     }
@@ -635,7 +635,7 @@ worker_thread (void *vp)
     /* Read the block data and uncompress it. */
     r = lzma_block_decoder (&strm, &block);
     if (r != LZMA_OK) {
-      fprintf (stderr, "%s: invalid block (error %d)\n", global->filename, r);
+      fprintf (stderr, "%s: invalid block (error %u)\n", global->filename, r);
       return &state->status;
     }
 
@@ -684,7 +684,7 @@ worker_thread (void *vp)
         break;
       if (r != LZMA_OK) {
         fprintf (stderr,
-                 "%s: could not parse block data (error %d)\n",
+                 "%s: could not parse block data (error %u)\n",
                  global->filename, r);
         return &state->status;
       }
diff --git a/cat/filesystems.c b/cat/filesystems.c
index 44defe0..0e64e00 100644
--- a/cat/filesystems.c
+++ b/cat/filesystems.c
@@ -868,7 +868,7 @@ write_row (const char *name, const char *type,
     strings[len++] = vfs_label;
   if ((columns & COLUMN_MBR)) {
     if (mbr_id >= 0) {
-      snprintf (mbr_id_str, sizeof mbr_id_str, "%02x", mbr_id);
+      snprintf (mbr_id_str, sizeof mbr_id_str, "%02x", (unsigned) mbr_id);
       strings[len++] = mbr_id_str;
     } else
       strings[len++] = NULL;
diff --git a/cat/ls.c b/cat/ls.c
index 3bced54..987dcef 100644
--- a/cat/ls.c
+++ b/cat/ls.c
@@ -702,7 +702,7 @@ output_int64_perms (int64_t i)
 {
   next_field ();
   /* csv doesn't need escaping */
-  if (printf ("%04" PRIo64, i) < 0) {
+  if (printf ("%04" PRIo64, (uint64_t) i) < 0) {
     perror ("printf");
     exit (EXIT_FAILURE);
   }
@@ -774,7 +774,8 @@ output_int64_dev (int64_t i)
   next_field ();
 
   /* csv doesn't need escaping */
-  if (printf ("%d:%d", major (dev), minor (dev)) < 0) {
+  if (printf ("%ju:%ju",
+              (uintmax_t) major (dev), (uintmax_t) minor (dev)) < 0) {
     perror ("printf");
     exit (EXIT_FAILURE);
   }
diff --git a/daemon/ext2.c b/daemon/ext2.c
index 8ef6d5f..9142a38 100644
--- a/daemon/ext2.c
+++ b/daemon/ext2.c
@@ -780,11 +780,16 @@ do_get_e2generation (const char *filename)
     return -1;
   }
 
-  if (sscanf (out, "%" SCNu64, &ret) != 1) {
+  if (sscanf (out, "%" SCNi64, &ret) != 1) {
     reply_with_error ("cannot parse output from '%s' command: %s",
                       "lsattr", out);
     return -1;
   }
+  if (ret < 0) {
+    reply_with_error ("unexpected negative number from '%s' command: %s",
+                      "lsattr", out);
+    return -1;
+  }
 
   return ret;
 }
diff --git a/daemon/file.c b/daemon/file.c
index bb3b3c1..c609a01 100644
--- a/daemon/file.c
+++ b/daemon/file.c
@@ -140,7 +140,7 @@ do_chmod (int mode, const char *path)
   CHROOT_OUT;
 
   if (r == -1) {
-    reply_with_perror ("%s: 0%o", path, mode);
+    reply_with_perror ("%s: 0%o", path, (unsigned) mode);
     return -1;
   }
 
diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c
index 7f4b2f2..ee0aa43 100644
--- a/daemon/guestfsd.c
+++ b/daemon/guestfsd.c
@@ -224,7 +224,8 @@ main (int argc, char *argv[])
       exit (EXIT_SUCCESS);
 
     default:
-      fprintf (stderr, "guestfsd: unexpected command line option 0x%x\n", c);
+      fprintf (stderr, "guestfsd: unexpected command line option 0x%x\n",
+               (unsigned) c);
       exit (EXIT_FAILURE);
     }
   }
diff --git a/daemon/parted.c b/daemon/parted.c
index b516067..cb6c486 100644
--- a/daemon/parted.c
+++ b/daemon/parted.c
@@ -752,7 +752,7 @@ do_part_get_mbr_id (const char *device, int partnum)
   udev_settle ();
 
   /* It's printed in hex ... */
-  int id;
+  unsigned id;
   if (sscanf (out, "%x", &id) != 1) {
     reply_with_error ("sfdisk --print-id: cannot parse output: %s", out);
     return -1;
@@ -775,7 +775,8 @@ do_part_set_mbr_id (const char *device, int partnum, int idbyte)
   snprintf (partnum_str, sizeof partnum_str, "%d", partnum);
 
   char idbyte_str[16];
-  snprintf (idbyte_str, sizeof partnum_str, "%x", idbyte); /* NB: hex */
+  /* NB: hex */
+  snprintf (idbyte_str, sizeof partnum_str, "%x", (unsigned) idbyte);
 
   CLEANUP_FREE char *err = NULL;
   int r;
diff --git a/daemon/proto.c b/daemon/proto.c
index 7ae8c66..df63bfd 100644
--- a/daemon/proto.c
+++ b/daemon/proto.c
@@ -157,19 +157,20 @@ main_loop (int _sock)
 
     /* Check the version etc. */
     if (hdr.prog != GUESTFS_PROGRAM) {
-      reply_with_error ("wrong program (%d)", hdr.prog);
+      reply_with_error ("wrong program (%u)", hdr.prog);
       goto cont;
     }
     if (hdr.vers != GUESTFS_PROTOCOL_VERSION) {
-      reply_with_error ("wrong protocol version (%d)", hdr.vers);
+      reply_with_error ("wrong protocol version (%u)", hdr.vers);
       goto cont;
     }
     if (hdr.direction != GUESTFS_DIRECTION_CALL) {
-      reply_with_error ("unexpected message direction (%d)", hdr.direction);
+      reply_with_error ("unexpected message direction (%d)",
+                        (int) hdr.direction);
       goto cont;
     }
     if (hdr.status != GUESTFS_STATUS_OK) {
-      reply_with_error ("unexpected message status (%d)", hdr.status);
+      reply_with_error ("unexpected message status (%d)", (int) hdr.status);
       goto cont;
     }
 
@@ -444,8 +445,9 @@ receive_file (receive_cb cb, void *opaque)
 
     if (verbose)
       fprintf (stderr,
-               "guestfsd: receive_file: got chunk: cancel = 0x%x, len = %d, buf = %p\n",
-               chunk.cancel, chunk.data.data_len, chunk.data.data_val);
+               "guestfsd: receive_file: got chunk: cancel = 0x%x, len = %u, buf = %p\n",
+               (unsigned) chunk.cancel,
+               chunk.data.data_len, chunk.data.data_val);
 
     if (chunk.cancel != 0 && chunk.cancel != 1) {
       fprintf (stderr,
diff --git a/daemon/umask.c b/daemon/umask.c
index 52e854e..475c820 100644
--- a/daemon/umask.c
+++ b/daemon/umask.c
@@ -36,7 +36,7 @@ do_umask (int mask)
   int r;
 
   if (mask < 0 || mask > 0777) {
-    reply_with_error ("0%o: mask negative or out of range", mask);
+    reply_with_error ("0%o: mask negative or out of range", (unsigned) mask);
     return -1;
   }
 
diff --git a/daemon/zero.c b/daemon/zero.c
index 505c4bb..d152210 100644
--- a/daemon/zero.c
+++ b/daemon/zero.c
@@ -172,7 +172,7 @@ do_zero_device (const char *device)
     if (!is_zero (buf, sizeof buf)) {
       r = pwrite (fd, zero_buf, n, pos);
       if (r == -1) {
-        reply_with_perror ("pwrite: %s (with %" PRId64 " bytes left to write)",
+        reply_with_perror ("pwrite: %s (with %" PRIu64 " bytes left to write)",
                            device, size);
         close (fd);
         return -1;
diff --git a/diff/diff.c b/diff/diff.c
index 13ecca1..1261439 100644
--- a/diff/diff.c
+++ b/diff/diff.c
@@ -994,7 +994,7 @@ output_binary (const char *s, size_t len)
             exit (EXIT_FAILURE);
           }
         } else {
-          if (printf ("\\x%2x", s[i]) < 0) {
+          if (printf ("\\x%2x", (unsigned) s[i]) < 0) {
             perror ("printf");
             exit (EXIT_FAILURE);
           }
@@ -1054,7 +1054,7 @@ output_int64_perms (int64_t i)
 {
   next_field ();
   /* csv doesn't need escaping */
-  if (printf ("%04" PRIo64, i) < 0) {
+  if (printf ("%04" PRIo64, (uint64_t) i) < 0) {
     perror ("printf");
     exit (EXIT_FAILURE);
   }
@@ -1126,7 +1126,8 @@ output_int64_dev (int64_t i)
   next_field ();
 
   /* csv doesn't need escaping */
-  if (printf ("%d:%d", major (dev), minor (dev)) < 0) {
+  if (printf ("%ju:%ju",
+              (uintmax_t) major (dev), (uintmax_t) minor (dev)) < 0) {
     perror ("printf");
     exit (EXIT_FAILURE);
   }
diff --git a/fish/alloc.c b/fish/alloc.c
index b40284a..9f41915 100644
--- a/fish/alloc.c
+++ b/fish/alloc.c
@@ -97,7 +97,7 @@ parse_size (const char *str, off_t *size_rtn)
   xerr = xstrtoull (str, NULL, 0, &size, "0kKMGTPEZY");
   if (xerr != LONGINT_OK) {
     fprintf (stderr,
-             _("%s: invalid integer parameter (%s returned %d)\n"),
+             _("%s: invalid integer parameter (%s returned %u)\n"),
              "parse_size", "xstrtoull", xerr);
     return -1;
   }
diff --git a/fish/rc.c b/fish/rc.c
index 9ccd5f3..9b0c9c5 100644
--- a/fish/rc.c
+++ b/fish/rc.c
@@ -40,8 +40,8 @@
 /* Because this is a Unix domain socket, the total path length must be
  * under 108 bytes.
  */
-#define SOCKET_DIR "/tmp/.guestfish-%d" /* euid */
-#define SOCKET_PATH "/tmp/.guestfish-%d/socket-%d" /* euid, pid */
+#define SOCKET_DIR "/tmp/.guestfish-%ju" /* euid */
+#define SOCKET_PATH "/tmp/.guestfish-%ju/socket-%ju" /* euid, pid */
 
 static void
 create_sockdir (void)
@@ -52,7 +52,7 @@ create_sockdir (void)
   struct stat statbuf;
 
   /* Create the directory, and ensure it is owned by the user. */
-  snprintf (dir, sizeof dir, SOCKET_DIR, euid);
+  snprintf (dir, sizeof dir, SOCKET_DIR, (uintmax_t) euid);
   r = mkdir (dir, 0700);
   if (r == -1 && errno != EEXIST) {
   error:
@@ -79,7 +79,7 @@ create_sockpath (pid_t pid, char *sockpath, size_t len,
 
   create_sockdir ();
 
-  snprintf (sockpath, len, SOCKET_PATH, euid, pid);
+  snprintf (sockpath, len, SOCKET_PATH, (uintmax_t) euid, (uintmax_t) pid);
 
   addr->sun_family = AF_UNIX;
   strcpy (addr->sun_path, sockpath);
diff --git a/generator/bindtests.ml b/generator/bindtests.ml
index 9558a74..5358ff1 100644
--- a/generator/bindtests.ml
+++ b/generator/bindtests.ml
@@ -159,7 +159,7 @@ fill_lvm_pv (guestfs_h *g, struct guestfs_lvm_pv *pv, size_t i)
           pr "  {\n";
           pr "    size_t i;\n";
           pr "    for (i = 0; i < %s_size; ++i)\n" n;
-          pr "      fprintf (fp, \"<%%02x>\", %s[i]);\n" n;
+          pr "      fprintf (fp, \"<%%02x>\", (unsigned) %s[i]);\n" n;
           pr "    fprintf (fp, \"\\n\");\n";
           pr "  }\n";
         | OptString n -> pr "  fprintf (fp, \"%%s\\n\", %s ? %s : \"null\");\n" n n
diff --git a/generator/daemon.ml b/generator/daemon.ml
index 0c98d14..1825de4 100644
--- a/generator/daemon.ml
+++ b/generator/daemon.ml
@@ -564,12 +564,12 @@ cleanup_free_mountable (mountable_t *mountable)
                  pr "      r->%s[i++] = tok[j];\n" name;
                  pr "  }\n";
              | FBytes ->
-                 pr "  if (sscanf (tok, \"%%\"SCNu64, &r->%s) != 1) {\n" name;
+                 pr "  if (sscanf (tok, \"%%\" SCNi64, &r->%s) != 1) {\n" name;
                  pr "    fprintf (stderr, \"%%s: failed to parse size '%%s' from token %%s\\n\", __func__, tok, \"%s\");\n" name;
                  pr "    return -1;\n";
                  pr "  }\n";
              | FInt64 ->
-                 pr "  if (sscanf (tok, \"%%\"SCNi64, &r->%s) != 1) {\n" name;
+                 pr "  if (sscanf (tok, \"%%\" SCNi64, &r->%s) != 1) {\n" name;
                  pr "    fprintf (stderr, \"%%s: failed to parse int '%%s' from token %%s\\n\", __func__, tok, \"%s\");\n" name;
                  pr "    return -1;\n";
                  pr "  }\n";
diff --git a/generator/fish.ml b/generator/fish.ml
index 05bbdad..6f68e65 100644
--- a/generator/fish.ml
+++ b/generator/fish.ml
@@ -249,10 +249,10 @@ Guestfish will prompt for these separately."
     pr "print_%s_list (struct guestfs_%s_list *%ss)\n"
       typ typ typ;
     pr "{\n";
-    pr "  unsigned int i;\n";
+    pr "  size_t i;\n";
     pr "\n";
     pr "  for (i = 0; i < %ss->len; ++i) {\n" typ;
-    pr "    printf (\"[%%d] = {\\n\", i);\n";
+    pr "    printf (\"[%%zu] = {\\n\", i);\n";
     pr "    print_%s_indent (&%ss->val[i], \"  \");\n" typ typ;
     pr "    printf (\"}\\n\");\n";
     pr "  }\n";
@@ -270,7 +270,7 @@ Guestfish will prompt for these separately."
       pr "print_%s_indent (struct guestfs_%s *%s, const char *indent)\n" typ typ typ;
       pr "{\n";
       if needs_i then (
-        pr "  unsigned int i;\n";
+        pr "  size_t i;\n";
         pr "\n"
       );
       List.iter (
@@ -288,7 +288,8 @@ Guestfish will prompt for these separately."
             pr "    if (c_isprint (%s->%s[i]))\n" typ name;
             pr "      printf (\"%%c\", %s->%s[i]);\n" typ name;
             pr "    else\n";
-            pr "      printf (\"\\\\x%%02x\", %s->%s[i]);\n" typ name;
+            pr "      printf (\"\\\\x%%02x\", (unsigned) %s->%s[i]);\n"
+               typ name;
             pr "  printf (\"\\n\");\n"
         | name, (FUInt64|FBytes) ->
             pr "  printf (\"%%s%s: %%\" PRIu64 \"\\n\", indent, %s->%s);\n"
@@ -422,7 +423,7 @@ Guestfish will prompt for these separately."
           indent fn expr;
         pr "%s  if (xerr != LONGINT_OK) {\n" indent;
         pr "%s    fprintf (stderr,\n" indent;
-        pr "%s             _(\"%%s: %%s: invalid integer parameter (%%s returned %%d)\\n\"),\n" indent;
+        pr "%s             _(\"%%s: %%s: invalid integer parameter (%%s returned %%u)\\n\"),\n" indent;
         pr "%s             cmd, \"%s\", \"%s\", xerr);\n" indent name fn;
         pr "%s    goto %s;\n" indent out;
         pr "%s  }\n" indent;
@@ -585,9 +586,9 @@ Guestfish will prompt for these separately."
             | None ->
                 pr "  printf (\"%%d\\n\", r);\n";
             | Some FishOutputOctal ->
-                pr "  printf (\"%%s%%o\\n\", r != 0 ? \"0\" : \"\", r);\n";
+                pr "  printf (\"%%s%%o\\n\", r != 0 ? \"0\" : \"\", (unsigned) r);\n";
             | Some FishOutputHexadecimal ->
-                pr "  printf (\"%%s%%x\\n\", r != 0 ? \"0x\" : \"\", r);\n"
+                pr "  printf (\"%%s%%x\\n\", r != 0 ? \"0x\" : \"\", (unsigned) r);\n"
            )
        | RInt64 _ ->
            pr "  if (r == -1) goto out;\n";
@@ -598,7 +599,7 @@ Guestfish will prompt for these separately."
             | Some FishOutputOctal ->
                 pr "  printf (\"%%s%%\" PRIo64 \"\\n\", r != 0 ? \"0\" : \"\", r);\n";
             | Some FishOutputHexadecimal ->
-                pr "  printf (\"%%s%%\" PRIx64 \"\\n\", r != 0 ? \"0x\" : \"\", r);\n"
+                pr "  printf (\"%%s%%\" PRIx64 \"\\n\", r != 0 ? \"0x\" : \"\", (uint64_t) r);\n"
            )
        | RBool _ ->
            pr "  if (r == -1) goto out;\n";
diff --git a/make-fs/make-fs.c b/make-fs/make-fs.c
index cbf49d9..980bfeb 100644
--- a/make-fs/make-fs.c
+++ b/make-fs/make-fs.c
@@ -620,7 +620,7 @@ parse_size (const char *str, uint64_t estimate, uint64_t *size_rtn)
   xerr = xstrtoull (str, NULL, 0, &size, "0kKMGTPEZY");
   if (xerr != LONGINT_OK) {
     fprintf (stderr,
-             _("%s: %s: invalid size parameter '%s' (%s returned %d)\n"),
+             _("%s: %s: invalid size parameter '%s' (%s returned %u)\n"),
              guestfs_int_program_name, "parse_size", str, "xstrtoull", xerr);
     return -1;
   }
diff --git a/p2v/main.c b/p2v/main.c
index 666faf1..be32e4b 100644
--- a/p2v/main.c
+++ b/p2v/main.c
@@ -312,8 +312,9 @@ partition_parent (dev_t part_dev)
   size_t len = 0;
   unsigned parent_major, parent_minor;
 
-  if (asprintf (&path, "/sys/dev/block/%d:%d/../dev",
-                major (part_dev), minor (part_dev)) == -1) {
+  if (asprintf (&path, "/sys/dev/block/%ju:%ju/../dev",
+                (uintmax_t) major (part_dev),
+                (uintmax_t) minor (part_dev)) == -1) {
     perror ("asprintf");
     exit (EXIT_FAILURE);
   }
diff --git a/src/actions-support.c b/src/actions-support.c
index e671ed8..23b9ba7 100644
--- a/src/actions-support.c
+++ b/src/actions-support.c
@@ -38,25 +38,25 @@ guestfs_int_check_reply_header (guestfs_h *g,
                               unsigned int proc_nr, unsigned int serial)
 {
   if (hdr->prog != GUESTFS_PROGRAM) {
-    error (g, "wrong program (%d/%d)", hdr->prog, GUESTFS_PROGRAM);
+    error (g, "wrong program (%u/%d)", hdr->prog, GUESTFS_PROGRAM);
     return -1;
   }
   if (hdr->vers != GUESTFS_PROTOCOL_VERSION) {
-    error (g, "wrong protocol version (%d/%d)",
+    error (g, "wrong protocol version (%u/%d)",
            hdr->vers, GUESTFS_PROTOCOL_VERSION);
     return -1;
   }
   if (hdr->direction != GUESTFS_DIRECTION_REPLY) {
     error (g, "unexpected message direction (%d/%d)",
-           hdr->direction, GUESTFS_DIRECTION_REPLY);
+           (int) hdr->direction, GUESTFS_DIRECTION_REPLY);
     return -1;
   }
   if (hdr->proc != proc_nr) {
-    error (g, "unexpected procedure number (%d/%d)", hdr->proc, proc_nr);
+    error (g, "unexpected procedure number (%d/%u)", (int) hdr->proc, proc_nr);
     return -1;
   }
   if (hdr->serial != serial) {
-    error (g, "unexpected serial (%d/%d)", hdr->serial, serial);
+    error (g, "unexpected serial (%u/%u)", hdr->serial, serial);
     return -1;
   }
 
diff --git a/src/appliance.c b/src/appliance.c
index 2167ac3..2645cca 100644
--- a/src/appliance.c
+++ b/src/appliance.c
@@ -229,7 +229,7 @@ build_supermin_appliance (guestfs_h *g,
    */
   len = strlen (tmpdir) + 128;
   char cachedir[len];
-  snprintf (cachedir, len, "%s/.guestfs-%d", tmpdir, uid);
+  snprintf (cachedir, len, "%s/.guestfs-%ju", tmpdir, (uintmax_t) uid);
   char lockfile[len];
   snprintf (lockfile, len, "%s/lock", cachedir);
   char appliancedir[len];
@@ -244,8 +244,8 @@ build_supermin_appliance (guestfs_h *g,
   if (lstat (cachedir, &statbuf) == -1)
     return 0;
   if (statbuf.st_uid != uid) {
-    error (g, _("security: cached appliance %s is not owned by UID %d"),
-           cachedir, uid);
+    error (g, _("security: cached appliance %s is not owned by UID %ju"),
+           cachedir, (uintmax_t) uid);
     return -1;
   }
   if (!S_ISDIR (statbuf.st_mode)) {
diff --git a/src/fuse.c b/src/fuse.c
index 3fdb1d4..332c1be 100644
--- a/src/fuse.c
+++ b/src/fuse.c
@@ -345,8 +345,8 @@ mount_local_access (const char *path, int mask)
 
   debug (g, "%s: "
          "testing access mask%s%s%s%s: "
-         "caller UID:GID = %d:%d, "
-         "file UID:GID = %d:%d, "
+         "caller UID:GID = %ju:%ju, "
+         "file UID:GID = %ju:%ju, "
          "file mode = %o, "
          "result = %s",
          path,
@@ -354,8 +354,8 @@ mount_local_access (const char *path, int mask)
          mask & W_OK ? " W_OK" : "",
          mask & X_OK ? " X_OK" : "",
          mask == 0 ? " 0" : "",
-         fuse->uid, fuse->gid,
-         statbuf.st_uid, statbuf.st_gid,
+         (uintmax_t) fuse->uid, (uintmax_t) fuse->gid,
+         (uintmax_t) statbuf.st_uid, (uintmax_t) statbuf.st_gid,
          statbuf.st_mode,
          ok ? "OK" : "EACCESS");
 
@@ -402,7 +402,7 @@ mount_local_mknod (const char *path, mode_t mode, dev_t rdev)
 {
   int r;
   DECL_G ();
-  DEBUG_CALL ("%s, 0%o, 0x%lx", path, mode, (long) rdev);
+  DEBUG_CALL ("%s, 0%o, 0x%jx", path, mode, (uintmax_t) rdev);
 
   if (g->ml_read_only) return -EROFS;
 
@@ -548,7 +548,7 @@ mount_local_chown (const char *path, uid_t uid, gid_t gid)
 {
   int r;
   DECL_G ();
-  DEBUG_CALL ("%s, %ld, %ld", path, (long) uid, (long) gid);
+  DEBUG_CALL ("%s, %ju, %ju", path, (uintmax_t) uid, (uintmax_t) gid);
 
   if (g->ml_read_only) return -EROFS;
 
@@ -630,7 +630,7 @@ mount_local_open (const char *path, struct fuse_file_info *fi)
 {
   int flags = fi->flags & O_ACCMODE;
   DECL_G ();
-  DEBUG_CALL ("%s, 0%o", path, fi->flags);
+  DEBUG_CALL ("%s, 0%o", path, (unsigned) fi->flags);
 
   if (g->ml_read_only && flags != O_RDONLY)
     return -EROFS;
diff --git a/src/handle.c b/src/handle.c
index 51b9572..12c1fb2 100644
--- a/src/handle.c
+++ b/src/handle.c
@@ -336,7 +336,7 @@ guestfs_close (guestfs_h *g)
                                       trace_msg, strlen (trace_msg));
   }
 
-  debug (g, "closing guestfs handle %p (state %d)", g, g->state);
+  debug (g, "closing guestfs handle %p (state %d)", g, (int) g->state);
 
   if (g->state != CONFIG)
     shutdown_backend (g, 0);
diff --git a/src/launch-libvirt.c b/src/launch-libvirt.c
index f46782c..1c0bfac 100644
--- a/src/launch-libvirt.c
+++ b/src/launch-libvirt.c
@@ -857,7 +857,8 @@ debug_appliance_permissions (guestfs_h *g)
   CLEANUP_FREE char *cachedir = guestfs_get_cachedir (g);
   CLEANUP_FREE char *appliance = NULL;
 
-  appliance = safe_asprintf (g, "%s/.guestfs-%d", cachedir, geteuid ());
+  appliance = safe_asprintf (g, "%s/.guestfs-%ju",
+                             cachedir, (uintmax_t) geteuid ());
 
   guestfs_int_cmd_add_arg (cmd, "ls");
   guestfs_int_cmd_add_arg (cmd, "-a");
diff --git a/src/launch.c b/src/launch.c
index fd5479e..343f4ea 100644
--- a/src/launch.c
+++ b/src/launch.c
@@ -86,7 +86,7 @@ guestfs_impl_launch (guestfs_h *g)
 
     debug (g, "launch: tmpdir=%s", g->tmpdir);
     debug (g, "launch: umask=0%03o", get_umask (g));
-    debug (g, "launch: euid=%d", geteuid ());
+    debug (g, "launch: euid=%ju", (uintmax_t) geteuid ());
   }
 
   /* Launch the appliance. */
diff --git a/src/proto.c b/src/proto.c
index 4ddd164..815a4d2 100644
--- a/src/proto.c
+++ b/src/proto.c
@@ -527,7 +527,7 @@ recv_from_daemon (guestfs_h *g, uint32_t *size_rtn, void **buf_rtn)
   if (*size_rtn == GUESTFS_LAUNCH_FLAG) {
     if (g->state != LAUNCHING)
       error (g, _("received magic signature from guestfsd, but in state %d"),
-             g->state);
+             (int) g->state);
     else {
       g->state = READY;
       guestfs_int_call_callbacks_void (g, GUESTFS_EVENT_LAUNCH_DONE);
diff --git a/test-tool/test-tool.c b/test-tool/test-tool.c
index f41b8fd..def21e2 100644
--- a/test-tool/test-tool.c
+++ b/test-tool/test-tool.c
@@ -151,7 +151,7 @@ main (int argc, char *argv[])
 
     default:
       fprintf (stderr,
-               _("libguestfs-test-tool: unexpected command line option 0x%x\n"),
+               _("libguestfs-test-tool: unexpected command line option 0x%d\n"),
                c);
       exit (EXIT_FAILURE);
     }
-- 
2.3.1




More information about the Libguestfs mailing list