fix overflow corner case in strtoul-family functions
authorRich Felker <dalias@aerifal.cx>
Tue, 16 Sep 2014 20:08:53 +0000 (16:08 -0400)
committerRich Felker <dalias@aerifal.cx>
Mon, 30 Mar 2015 05:15:44 +0000 (01:15 -0400)
incorrect behavior occurred only in cases where the input overflows
unsigned long long, not just the (possibly lower) range limit for the
result type. in this case, processing of the '-' sign character was
not suppressed, and the function returned a value of 1 despite setting
errno to ERANGE.

(cherry picked from commit e2e1bb81485a37321d928a8d8b63f40b9d8fa228)

src/internal/intscan.c

index 69350efa6380ed65577cdcad84f7d470cd234b3c..65d497ec8a6fbabe6dafe65983d79c2bb9b2abf1 100644 (file)
@@ -83,6 +83,7 @@ unsigned long long __intscan(FILE *f, unsigned base, int pok, unsigned long long
                for (; val[c]<base; c=shgetc(f));
                errno = ERANGE;
                y = lim;
+               if (lim&1) neg = 0;
        }
 done:
        shunget(f);