X-Git-Url: https://pd.if.org/git/?p=pdclib;a=blobdiff_plain;f=functions%2Fstdlib%2Fstrtoll.c;fp=functions%2Fstdlib%2Fstrtoll.c;h=b9b6627b6ed322cdacc689b4c4f3d43afbf20e22;hp=fbe837d986ed4f51f2823ed9d4916ccf2fc73c14;hb=d02f38605b53cdff5460cc6b9e1b2a80c3a2ba4c;hpb=3f6094115e79a45413f08361b68b71eb08da306e diff --git a/functions/stdlib/strtoll.c b/functions/stdlib/strtoll.c index fbe837d..b9b6627 100644 --- a/functions/stdlib/strtoll.c +++ b/functions/stdlib/strtoll.c @@ -13,19 +13,22 @@ #ifndef REGTEST +#include + long long int strtoll( const char * s, char ** endptr, int base ) { long long int rc; char sign = '+'; const char * p = _PDCLIB_strtox_prelim( s, &sign, &base ); + if ( base < 2 || base > 36 ) return 0; if ( sign == '+' ) { - rc = _PDCLIB_strtox_main( &p, base, LLONG_MAX, LLONG_MAX / base, LLONG_MAX % base, &sign ); + rc = _PDCLIB_strtox_main( &p, (unsigned)base, (uintmax_t)LLONG_MAX, (uintmax_t)( LLONG_MAX / base ), (uintmax_t)( LLONG_MAX % base ), &sign ); } else { /* FIXME: This breaks on some machines that round negatives wrongly */ - rc = _PDCLIB_strtox_main( &p, base, LLONG_MIN, LLONG_MIN / -base, -( LLONG_MIN % base ), &sign ); + rc = _PDCLIB_strtox_main( &p, (unsigned)base, (uintmax_t)LLONG_MIN, (uintmax_t)( LLONG_MIN / -base ), (uintmax_t)( -( LLONG_MIN % base ) ), &sign ); } if ( endptr != NULL ) *endptr = ( p != NULL ) ? (char *) p : (char *) s; return ( sign == '+' ) ? rc : -rc; @@ -43,12 +46,11 @@ long long int strtoll( const char * s, char ** endptr, int base ) #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( strtoll( "123", NULL, 10 ) == 123 );