[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: truncate.c fails to compile on make distcheck
From: |
Jim Meyering |
Subject: |
Re: truncate.c fails to compile on make distcheck |
Date: |
Thu, 26 Jun 2008 07:49:31 +0200 |
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]
>From 3d309aa725e529a5e90aacc5594565e21f966537 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Wed, 25 Jun 2008 23:15:06 +0200
Subject: [PATCH] truncate: handle the case in which off_t != intmax_t
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
* src/truncate.c (parse_len): Use a temporary of type intmax_t,
rather than off_t; detect out of range [OFF_T_MIN..OFF_T_MAX].
(main) [IF_LINT]: Initialize, to avoid an unwarranted
"may be used uninitialized" warning.
Reported by Michael Geng.
Signed-off-by: Pádraig Brady <address@hidden>
---
src/truncate.c | 21 ++++++++++++++++-----
1 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/src/truncate.c b/src/truncate.c
index 8febd58..2435a12 100644
--- a/src/truncate.c
+++ b/src/truncate.c
@@ -74,10 +74,21 @@ 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");
- errno = (e == LONGINT_OVERFLOW) ? EOVERFLOW : 0;
- return (e == LONGINT_OK) ? 0 : -1;
+ intmax_t tmp_size;
+ e = xstrtoimax (str, NULL, 10, &tmp_size, "EgGkKmMPtTYZ0");
+ if (e == LONGINT_OK
+ && !(OFF_T_MIN <= tmp_size && tmp_size <= OFF_T_MAX))
+ e = LONGINT_OVERFLOW;
+
+ if (e == LONGINT_OK)
+ {
+ errno = 0;
+ *size = tmp_size;
+ return 0;
+ }
+
+ errno = (e == LONGINT_OVERFLOW ? EOVERFLOW : 0);
+ return -1;
}
static void
@@ -243,7 +254,7 @@ int
main (int argc, char **argv)
{
bool got_size = false;
- off_t size;
+ off_t size IF_LINT (= 0);
rel_mode_t rel_mode = rm_abs;
mode_t omode;
int c, errors = 0, fd = -1, oflags;
--
1.5.6.66.g30faa
- truncate.c fails to compile on make distcheck, Michael Geng, 2008/06/25
- Re: truncate.c fails to compile on make distcheck, Pádraig Brady, 2008/06/25
- Re: truncate.c fails to compile on make distcheck,
Jim Meyering <=
- Re: truncate.c fails to compile on make distcheck, Pádraig Brady, 2008/06/26
- Re: truncate.c fails to compile on make distcheck, Jim Meyering, 2008/06/26
- Re: truncate.c fails to compile on make distcheck, Pádraig Brady, 2008/06/26
- Re: truncate.c fails to compile on make distcheck, Jim Meyering, 2008/06/26
- Re: truncate.c fails to compile on make distcheck, Pádraig Brady, 2008/06/26
- Re: truncate.c fails to compile on make distcheck, Jim Meyering, 2008/06/27
- Re: truncate.c fails to compile on make distcheck, Pádraig Brady, 2008/06/27
- Re: truncate.c fails to compile on make distcheck, Jim Meyering, 2008/06/27
- Re: truncate.c fails to compile on make distcheck, Paul Eggert, 2008/06/27
- Re: truncate.c fails to compile on make distcheck, Pádraig Brady, 2008/06/27