X-Git-Url: https://pd.if.org/git/?p=pdclib;a=blobdiff_plain;f=functions%2Finttypes%2Fstrtoumax.c;h=c54cfce481ff087c0e234df85a121b37daab6f1e;hp=9c9833eda92bd367d462f734e1fde975abf0c9b8;hb=dd71cbbfbd68cd8c653277a0c1f70ab2b179421c;hpb=bdad1f82d0c0aa0b83e8b195303d7957c578da2e diff --git a/functions/inttypes/strtoumax.c b/functions/inttypes/strtoumax.c index 9c9833e..c54cfce 100644 --- a/functions/inttypes/strtoumax.c +++ b/functions/inttypes/strtoumax.c @@ -78,20 +78,30 @@ int main( void ) errno = 0; /* uintmax_t -> long long -> 64 bit */ #if UINTMAX_MAX >> 63 == 1 - /* testing "even" overflow, i.e. base is power of two */ + /* testing "odd" overflow, i.e. base is not power of two */ TESTCASE( strtoumax( "18446744073709551615", NULL, 0 ) == UINTMAX_MAX ); TESTCASE( errno == 0 ); TESTCASE( strtoumax( "18446744073709551616", NULL, 0 ) == UINTMAX_MAX ); TESTCASE( errno == ERANGE ); - /* TODO: test "odd" overflow, i.e. base is not power of two */ + /* testing "even" overflow, i.e. base is power of two */ + errno = 0; + TESTCASE( strtoumax( "0xFFFFFFFFFFFFFFFF", NULL, 0 ) == UINTMAX_MAX ); + TESTCASE( errno == 0 ); + TESTCASE( strtoumax( "0x10000000000000000", NULL, 0 ) == UINTMAX_MAX ); + TESTCASE( errno == ERANGE ); /* uintmax_t -> long long -> 128 bit */ #elif UINTMAX_MAX >> 127 == 1 - /* testing "even" overflow, i.e. base is power of two */ + /* testing "odd" overflow, i.e. base is not power of two */ TESTCASE( strtoumax( "340282366920938463463374607431768211455", NULL, 0 ) == UINTMAX_MAX ); TESTCASE( errno == 0 ); TESTCASE( strtoumax( "340282366920938463463374607431768211456", NULL, 0 ) == UINTMAX_MAX ); TESTCASE( errno == ERANGE ); - /* TODO: test "odd" overflow, i.e. base is not power of two */ + /* testing "even" everflow, i.e. base is power of two */ + errno = 0; + TESTCASE( strtoumax( "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", NULL, 0 ) == UINTMAX_MAX ); + TESTCASE( errno == 0 ); + TESTCASE( strtoumax( "0x100000000000000000000000000000000", NULL, 0 ) == UINTMAX_MAX ); + TESTCASE( errno == ERANGE ); #else #error Unsupported width of 'uintmax_t' (neither 64 nor 128 bit). #endif