X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstdlib%2Fstrtoll.c;h=aa91163842a09bc4923a64c95a1e65333d9c49d2;hb=0d54a75af25ca44411e7c4190cc2a93a390e61a2;hp=fbe837d986ed4f51f2823ed9d4916ccf2fc73c14;hpb=23e170071520809fd7b2ea3514e48399358362f2;p=pdclib.old diff --git a/functions/stdlib/strtoll.c b/functions/stdlib/strtoll.c index fbe837d..aa91163 100644 --- a/functions/stdlib/strtoll.c +++ b/functions/stdlib/strtoll.c @@ -1,7 +1,5 @@ /* $Id$ */ -/* Release $Name$ */ - /* strtoll( const char *, char * *, int ) This file is part of the Public Domain C Library (PDCLib). @@ -13,19 +11,23 @@ #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 = (long long int)_PDCLIB_strtox_main( &p, (unsigned)base, (uintmax_t)LLONG_MAX, (uintmax_t)( LLONG_MAX / base ), (int)( 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 ); + /* FIXME: Sign error not caught by testdriver */ + rc = (long long int)_PDCLIB_strtox_main( &p, (unsigned)base, (uintmax_t)LLONG_MIN, (uintmax_t)( LLONG_MIN / -base ), (int)( -( LLONG_MIN % base ) ), &sign ); } if ( endptr != NULL ) *endptr = ( p != NULL ) ? (char *) p : (char *) s; return ( sign == '+' ) ? rc : -rc; @@ -43,12 +45,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 ); @@ -92,7 +93,7 @@ int main() TESTCASE( strtoll( "0x8000000000000000", NULL, 0 ) == LLONG_MAX ); TESTCASE( errno == ERANGE ); errno = 0; - TESTCASE( strtoll( "-0x7FFFFFFFFFFFFFFF", NULL, 0 ) == 0x8000000000000001 ); + TESTCASE( strtoll( "-0x7FFFFFFFFFFFFFFF", NULL, 0 ) == (long long)0x8000000000000001 ); TESTCASE( errno == 0 ); TESTCASE( strtoll( "-0x8000000000000000", NULL, 0 ) == LLONG_MIN ); TESTCASE( errno == 0 );