From e41c75c1bce4026795fc86074227e5965923fb47 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 17 Aug 1995 10:03:43 +0000 Subject: [PATCH] Some minor changes --- lang/cem/libcc.ansi/stdlib/strtol.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lang/cem/libcc.ansi/stdlib/strtol.c b/lang/cem/libcc.ansi/stdlib/strtol.c index 15911d525..ad9a5166c 100644 --- a/lang/cem/libcc.ansi/stdlib/strtol.c +++ b/lang/cem/libcc.ansi/stdlib/strtol.c @@ -29,7 +29,7 @@ static unsigned long string2long(register const char *nptr, char ** const endptr, int base, int is_signed) { - register int v; + register unsigned int v; register unsigned long val = 0; register int c; int ovfl = 0, sign = 1; @@ -64,8 +64,8 @@ string2long(register const char *nptr, char ** const endptr, else v = c - '0'; if (v >= base) break; - if (val > (ULONG_MAX - v) / base) ovfl++; - val = (val * base) + v; + if (val > (ULONG_MAX - v) / base) ++ovfl; + else val = (val * base) + v; } nptr++; } @@ -76,8 +76,8 @@ string2long(register const char *nptr, char ** const endptr, if (!ovfl) { /* Overflow is only possible when converting a signed long. - * val is unsigned long, so -LONG_MIN is converted to - * unsigned long. + * The "-(LONG_MIN+1)+(unsigned long) 1" construction is there + * to prevent overflow warnings on -LONG_MIN. */ if (is_signed && ( (sign < 0 && val > -(LONG_MIN+1)+(unsigned long) 1) @@ -92,5 +92,5 @@ string2long(register const char *nptr, char ** const endptr, else return LONG_MAX; else return ULONG_MAX; } - return (long) sign * val; + return (sign * val); }