Mail Archives: djgpp/2001/02/28/15:44:31
> From: "Rafael Garcia" <rafael AT geninfor DOT com>
> Newsgroups: comp.os.msdos.djgpp
> Date: Wed, 28 Feb 2001 14:09:30 +0100
>
> Hello all. I have found a bug in one of my functions due to an extrange
> behaviour of atoi() with bad data introduced by a user in a date. If you
> give 8-bit chars to atoi, it does not return cero. Does anybody know why?
It's a bug in the library; thanks for reporting it. Here's a patch
for the strtol function which is responsible for this bug:
--- src/libc/ansi/stdlib/strtol.c~0 Wed Aug 4 21:58:22 1999
+++ src/libc/ansi/stdlib/strtol.c Wed Feb 28 22:36:06 2001
@@ -60,7 +60,7 @@ strtol(const char *nptr, char **endptr,
cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX;
cutlim = cutoff % (unsigned long)base;
cutoff /= (unsigned long)base;
- for (acc = 0, any = 0;; c = *s++, c &= 0xff)
+ for (acc = 0, any = 0, c &= 0xff;; c = *s++, c &= 0xff)
{
if (isdigit(c))
c -= '0';
- Raw text -