X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstdlib%2Fstrtoul.c;h=68f790af7a44fff289c9482d2ac6e31b1f997198;hb=9507e63e4b8558c8a3337521853f80f72f83a689;hp=80bacec30aebbb8165d0d146f51fe56c54e8f572;hpb=fed7bd2546a24c265b7a4c74b2b2829a1738a1db;p=pdclib.old diff --git a/functions/stdlib/strtoul.c b/functions/stdlib/strtoul.c index 80bacec..68f790a 100644 --- a/functions/stdlib/strtoul.c +++ b/functions/stdlib/strtoul.c @@ -1,26 +1,25 @@ /* $Id$ */ -/* Release $Name$ */ - /* strtoul( const char *, char * *, int ) This file is part of the Public Domain C Library (PDCLib). Permission is granted to use, modify, and / or redistribute at will. */ -#define _PDCLIB_INT_H _PDCLIB_INT_H -#include <_PDCLIB_int.h> #include #include #ifndef REGTEST +#include + unsigned long int strtoul( const char * s, char ** endptr, int base ) { unsigned long int rc; char sign = '+'; const char * p = _PDCLIB_strtox_prelim( s, &sign, &base ); - rc = _PDCLIB_strtox_main( &p, base, ULONG_MAX, ULONG_MAX / base, ULONG_MAX % base, &sign ); + if ( base < 2 || base > 36 ) return 0; + rc = _PDCLIB_strtox_main( &p, (unsigned)base, (uintmax_t)ULONG_MAX, (uintmax_t)( ULONG_MAX / base ), (int)( ULONG_MAX % base ), &sign ); if ( endptr != NULL ) *endptr = ( p != NULL ) ? (char *) p : (char *) s; return ( sign == '+' ) ? rc : -rc; } @@ -31,12 +30,11 @@ unsigned long int strtoul( const char * s, char ** endptr, int base ) #include <_PDCLIB_test.h> #include -int main() +int main( void ) { char * endptr; /* this, to base 36, overflows even a 256 bit integer */ char overflow[] = "-ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ_"; - BEGIN_TESTS; errno = 0; /* basic functionality */ TESTCASE( strtoul( "123", NULL, 10 ) == 123 );