X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstdlib%2Fstrtoul.c;h=68f790af7a44fff289c9482d2ac6e31b1f997198;hb=f93d55176e4db9edfb1840054169003bcca4d1fb;hp=e38dbd678f36b95b736949467a3a244fe2385ae0;hpb=d0efaaaab9fdaccd83ced5aa74b40a9b3a391466;p=pdclib diff --git a/functions/stdlib/strtoul.c b/functions/stdlib/strtoul.c index e38dbd6..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. */ -#include <_PDCLIB_int.h> #include -#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 );