bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: truncate.c fails to compile on make distcheck


From: Pádraig Brady
Subject: Re: truncate.c fails to compile on make distcheck
Date: Thu, 26 Jun 2008 09:42:24 +0100
User-agent: Thunderbird 2.0.0.6 (X11/20071008)

Jim Meyering wrote:
> Pádraig Brady <address@hidden> wrote:
>> Jim Meyering wrote:
>>> Here's a tentative patch:
> ...
>> I reviewed all uses of off_t in the code and came up with
>> an almost identical patch, so I'm happy to go with the above.
> 
> Hi Pádraig,
> Thanks for checking.
> Here's what I've pushed:
> [I added the IF_LINT initializer]

Hmm, it's probably cleaner to assign *size unconditionally,
as I had done in my patch, but it doesn't really matter.

I also noticed this morning that some format specifiers also
assumed sizeof(off_t) == sizeof(intmax_t) and thus would
print garbage off the stack if this wasn't the case.

Attached is my current patch for reference.

thanks,
Pádraig.
>From 6e44a9d43a9c88cb943c5583c63b2c81bbb17e64 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?P=C3=A1draig=20Brady?= <address@hidden>
Date: Wed, 25 Jun 2008 19:27:40 +0100
Subject: [PATCH] truncate: Add support for systems without large file support

* src/truncate.c: don't assume off_t is same size as intmax_t

Signed-off-by: Pádraig Brady <address@hidden>
---
 src/truncate.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/truncate.c b/src/truncate.c
index f26fd45..044ae4e 100644
--- a/src/truncate.c
+++ b/src/truncate.c
@@ -73,8 +73,12 @@ static int
 parse_len (char const *str, off_t *size)
 {
   enum strtol_error e;
-  /* OFF_T_MAX = INTMAX_MAX */
-  e = xstrtoimax (str, NULL, 10, size, "EgGkKmMPtTYZ0");
+  intmax_t tmp_size; /* OFF_T_MAX <= INTMAX_MAX */
+  e = xstrtoimax (str, NULL, 10, &tmp_size, "EgGkKmMPtTYZ0");
+  if (e == LONGINT_OK &&
+      (tmp_size < OFF_T_MIN || tmp_size > OFF_T_MAX))
+    e = LONGINT_OVERFLOW;
+  *size = tmp_size;
   errno = (e == LONGINT_OVERFLOW) ? EOVERFLOW : 0;
   return (e == LONGINT_OK) ? 0 : -1;
 }
@@ -148,7 +152,7 @@ do_ftruncate (int fd, char const *fname, off_t ssize, 
rel_mode_t rel_mode)
         {
           error (0, 0,
                  _("overflow in %" PRIdMAX
-                   " * %zu byte blocks for file %s"), ssize, blksize,
+                   " * %zu byte blocks for file %s"), (intmax_t) ssize, 
blksize,
                  quote (fname));
           return 1;
         }
@@ -229,7 +233,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;
-- 
1.5.3.6


reply via email to

[Prev in Thread] Current Thread [Next in Thread]