]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
truncate: Fix integer portability issues
authorPádraig Brady <P@draigBrady.com>
Thu, 26 Jun 2008 10:10:13 +0000 (11:10 +0100)
committerJim Meyering <meyering@redhat.com>
Fri, 27 Jun 2008 06:11:21 +0000 (08:11 +0200)
* src/truncate.c: Explicitly convert from off_t to intmax_t
when printing numbers as they may be different types.
Also don't mix size_t and off_t types in operations as
the latter will be promoted to unsigned when these types
are the same size.

src/truncate.c

index 2435a12771c4b26576505683d71266ccb77c9ce6..02d41024b7819e00e90f3d788d25a3f6dece6ac6 100644 (file)
@@ -155,12 +155,13 @@ do_ftruncate (int fd, char const *fname, off_t ssize, rel_mode_t rel_mode)
     }
   if (block_mode)
     {
-      size_t const blksize = ST_BLKSIZE (sb);
+      off_t const blksize = ST_BLKSIZE (sb);
       if (ssize < OFF_T_MIN / blksize || ssize > OFF_T_MAX / blksize)
         {
           error (0, 0,
                  _("overflow in %" PRIdMAX
-                   " * %zu byte blocks for file %s"), ssize, blksize,
+                   " * %" PRIdMAX " byte blocks for file %s"),
+                 (intmax_t) ssize, (intmax_t) blksize,
                  quote (fname));
           return 1;
         }
@@ -241,7 +242,7 @@ do_ftruncate (int fd, char const *fname, off_t ssize, rel_mode_t rel_mode)
         {
           error (0, ftruncate_errno,
                  _("truncating %s at %" PRIdMAX " bytes"), quote (fname),
-                 nsize);
+                 (intmax_t) nsize);
           return 1;
         }
       return 0;