Mail Archives: djgpp-workers/2004/02/23/15:29:11
DJ Delorie wrote:
>
> > That isn't a range error IMO - the initial '-' is an illegal char,
> > so it shouldn't convert anything, and should return 0. From N869:
> >
> > [#4] The subject sequence is defined as the longest initial
> > subsequence of the input string, starting with the first
> > non-white-space character, that is of the expected form.
>
> ISO 9899/1999 explicitly allows '-' to be part of the expected form
> for strtoul. Negative numbers are outside its range.
>
> > In either case the 2.03 version of strtoul does NOT return ULONG_MAX
> > for -2, it simply performs the usual conversion modulo ULONG_MAX+1.
>
> Ok, *that* is a bug. Amusingly enough, glibc 2.3.2 has the same bug.
>
> At this point, I think the right next step is to create a test suite
> for these functions and post it to djgpp-workers (no need to subject
> the regular list with such detail). Once we agree on what the right
> results are, we can proceed with fixing them.
Moved from c.o.m.djgpp. Here is a test suite:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
int main(int argc, char **argv)
{
unsigned int n;
int i;
char s[25];
char *rem;
if (2 != argc) puts("Usage: djbug N");
else {
n = strtoul(argv[1], NULL, 10);
if (n > 10) puts("Max. N is 10");
else {
printf("Neg args should yield %lu and error\n",
(unsigned long)-1);
for (i = -n; i <= (int)n; i++) {
sprintf(s, "%djunk", i);
errno = 0;
printf("strtoul(\"%s\") = %lu",
s, strtoul(s, &rem, 10));
printf(" remnant \"%s\"\n", rem);
if (errno) perror("Error");
}
}
}
return 0;
} /* main */
--
Chuck F (cbfalconer AT yahoo DOT com) (cbfalconer AT worldnet DOT att DOT net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
- Raw text -