Pádraig Brady wrote, On 02/12/2013 04:18 AM:
> On 02/12/2013 04:45 AM, Assaf Gordon wrote:
>> On Feb 11, 2013, at 20:32, Pádraig Brady <p...@draigbrady.com> wrote:
>>> On 02/11/2013 08:47 PM, Assaf Gordon wrote:
>>>> +  if (errno != 0 && (errno != EINVAL))
>>>
>>> It might be better to do:
>>>
>>> if (errno == ERANGE)
>>>   error ();
>>>
>>
>> I was thinking about that, my only concern was since we're already dealing 
>> with non-standard code, should we worry about an even weirder implementation 
>> that might return something that's not ERANGE and not EINVAL?
> 
> The error message is just about ERANGE, so it's probably
> best to use just that value in the conditional.
> Reading the docs, EINVAL is the only other possibility.
> 

Attached updated patch.

Thanks!
  -gordon


>From ad72efaf534bf61c1c9afa8121aa07808016de3e Mon Sep 17 00:00:00 2001
From: Assaf Gordon <assafgor...@gmail.com>
Date: Tue, 12 Feb 2013 15:28:22 -0500
Subject: [PATCH] numfmt: fix strtol() bug

src/numfmt.c: on some system, strtol() returns EINVAL if no conversion
was performed. Ignore and continue if so. Abort only on ERANGE.
---
 src/numfmt.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/numfmt.c b/src/numfmt.c
index d87d8ef..9a321d6 100644
--- a/src/numfmt.c
+++ b/src/numfmt.c
@@ -970,7 +970,7 @@ parse_format_string (char const *fmt)
   i += strspn (fmt + i, " ");
   errno = 0;
   pad = strtol (fmt + i, &endptr, 10);
-  if (errno != 0)
+  if (errno == ERANGE)
     error (EXIT_FAILURE, 0,
            _("invalid format %s (width overflow)"), quote (fmt));
 
-- 
1.7.7.4

Reply via email to