X-Git-Url: https://pd.if.org/git/?p=pdclib;a=blobdiff_plain;f=functions%2Finttypes%2Fstrtoumax.c;h=f998338babfd5d6c0f674f3204fffc79ec49eef4;hp=0da7ec2889f31fffb2f510287e61a5d8dd5ad30c;hb=da0f3f353d417fed71f358a48d5d5394145e460d;hpb=45f394553721285e7bc6187419613c33915cce21 diff --git a/functions/inttypes/strtoumax.c b/functions/inttypes/strtoumax.c old mode 100755 new mode 100644 index 0da7ec2..f998338 --- a/functions/inttypes/strtoumax.c +++ b/functions/inttypes/strtoumax.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /* strtoumax( const char *, char * *, int ) This file is part of the Public Domain C Library (PDCLib). @@ -27,7 +25,7 @@ uintmax_t strtoumax( const char * _PDCLIB_restrict nptr, char ** _PDCLIB_restric #endif #ifdef TEST -#include <_PDCLIB_test.h> +#include "_PDCLIB_test.h" #include int main( void ) @@ -76,20 +74,32 @@ int main( void ) 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 */ +/* uintmax_t -> long long -> 64 bit */ +#if UINTMAX_MAX >> 63 == 1 + /* 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 */ -#elif UINTMAX_MAX == 0xffffffffffffffffffffffffffffffffLL /* 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 "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