X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstdlib%2Fstrtoul.c;h=d283efba8aa10cf235a91c7a65fc5339a8adabcc;hb=d02f38605b53cdff5460cc6b9e1b2a80c3a2ba4c;hp=98f5446254a9ff03dfddf553eb056f3d56736163;hpb=3f6094115e79a45413f08361b68b71eb08da306e;p=pdclib diff --git a/functions/stdlib/strtoul.c b/functions/stdlib/strtoul.c index 98f5446..d283efb 100644 --- a/functions/stdlib/strtoul.c +++ b/functions/stdlib/strtoul.c @@ -13,12 +13,15 @@ #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 ), (uintmax_t)( ULONG_MAX % base ), &sign ); if ( endptr != NULL ) *endptr = ( p != NULL ) ? (char *) p : (char *) s; return ( sign == '+' ) ? rc : -rc; } @@ -29,12 +32,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 );