X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstdlib%2Fstrtoull.c;h=ca9dd1936ee2fb46c11dddfaf5f424aa5147e3bb;hb=2829022b6506ec945c9f9143fd2d287a18349dd2;hp=a65779cfadd6be34fab012fca92f753d328aa736;hpb=e09c56012b4ba30db77af0c8ef2b4b494a1c4f50;p=pdclib.old diff --git a/functions/stdlib/strtoull.c b/functions/stdlib/strtoull.c index a65779c..ca9dd19 100644 --- a/functions/stdlib/strtoull.c +++ b/functions/stdlib/strtoull.c @@ -75,6 +75,24 @@ int main( void ) endptr = NULL; TESTCASE( strtoull( overflow, &endptr, 0 ) == 0 ); TESTCASE( endptr == overflow ); + errno = 0; +#if ULLONG_MAX == 0xffffffffffffffffLL + /* testing "even" overflow, i.e. base is power of two */ + TESTCASE( strtoull( "18446744073709551615", NULL, 0 ) == ULLONG_MAX ); + TESTCASE( errno == 0 ); + TESTCASE( strtoull( "18446744073709551616", NULL, 0 ) == ULLONG_MAX ); + TESTCASE( errno == ERANGE ); + /* TODO: test "odd" overflow, i.e. base is not power of two */ +#elif ULLONG_MAX == 0xffffffffffffffffffffffffffffffffLL + /* testing "even" overflow, i.e. base is power of two */ + TESTCASE( strtoull( "340282366920938463463374607431768211455", NULL, 0 ) == ULLONG_MAX ); + TESTCASE( errno == 0 ); + TESTCASE( strtoull( "340282366920938463463374607431768211456", NULL, 0 ) == ULLONG_MAX ); + TESTCASE( errno == ERANGE ); + /* TODO: test "odd" overflow, i.e. base is not power of two */ +#else +#error Unsupported width of 'long long' (neither 64 nor 128 bit). +#endif return TEST_RESULTS; }