X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstdlib%2Fstrtoull.c;h=929a96c3699c60a1686bde7cb9bc9ddab1733f5d;hb=12e17136786afb1775c9dc946cbe41f5e230c24a;hp=de7275a9b58881c92163293c1669e51ea8ae7862;hpb=fed7bd2546a24c265b7a4c74b2b2829a1738a1db;p=pdclib.old diff --git a/functions/stdlib/strtoull.c b/functions/stdlib/strtoull.c index de7275a..929a96c 100644 --- a/functions/stdlib/strtoull.c +++ b/functions/stdlib/strtoull.c @@ -8,19 +8,20 @@ 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 long int strtoull( const char * s, char ** endptr, int base ) { unsigned long long int rc; char sign = '+'; const char * p = _PDCLIB_strtox_prelim( s, &sign, &base ); - rc = _PDCLIB_strtox_main( &p, base, ULLONG_MAX, ULLONG_MAX / base, ULLONG_MAX % base, &sign ); + if ( base < 2 || base > 36 ) return 0; + rc = _PDCLIB_strtox_main( &p, (unsigned)base, (uintmax_t)ULLONG_MAX, (uintmax_t)( ULLONG_MAX / base ), (uintmax_t)( ULLONG_MAX % base ), &sign ); if ( endptr != NULL ) *endptr = ( p != NULL ) ? (char *) p : (char *) s; return ( sign == '+' ) ? rc : -rc; } @@ -31,12 +32,11 @@ unsigned long long int strtoull( 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( strtoull( "123", NULL, 10 ) == 123 );