X-Git-Url: https://pd.if.org/git/?p=pdclib;a=blobdiff_plain;f=functions%2Finttypes%2Fstrtoumax.c;h=0da7ec2889f31fffb2f510287e61a5d8dd5ad30c;hp=063e7ab681138c18d7c4e1055a8742181be7902d;hb=45f394553721285e7bc6187419613c33915cce21;hpb=a381f50d5325748b70096ac5f5d3f63ae4f6e18a diff --git a/functions/inttypes/strtoumax.c b/functions/inttypes/strtoumax.c index 063e7ab..0da7ec2 100755 --- a/functions/inttypes/strtoumax.c +++ b/functions/inttypes/strtoumax.c @@ -75,6 +75,24 @@ int main( void ) endptr = NULL; TESTCASE( strtoumax( overflow, &endptr, 0 ) == 0 ); TESTCASE( endptr == overflow ); + errno = 0; +#if UINTMAX_MAX == 0xffffffffffffffffLL + /* testing "even" overflow, i.e. base is 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 */ +#elif UINTMAX_MAX == 0xffffffffffffffffffffffffffffffffLL + /* testing "even" overflow, i.e. base is 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 */ +#else +#error Unsupported width of 'uintmax_t' (neither 64 nor 128 bit). +#endif return TEST_RESULTS; }