X-Git-Url: https://pd.if.org/git/?p=pdclib;a=blobdiff_plain;f=functions%2Fstdlib%2Fstrtoull.c;h=17d283fd6964336403b5043af10a89fea0ccb151;hp=a65779cfadd6be34fab012fca92f753d328aa736;hb=da0f3f353d417fed71f358a48d5d5394145e460d;hpb=54fc1aef7a9754a3daa803e47a59d76a8173d703 diff --git a/functions/stdlib/strtoull.c b/functions/stdlib/strtoull.c index a65779c..17d283f 100644 --- a/functions/stdlib/strtoull.c +++ b/functions/stdlib/strtoull.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /* strtoull( const char *, char * *, int ) This file is part of the Public Domain C Library (PDCLib). @@ -27,7 +25,7 @@ unsigned long long int strtoull( const char * s, char ** endptr, int base ) #endif #ifdef TEST -#include <_PDCLIB_test.h> +#include "_PDCLIB_test.h" #include int main( void ) @@ -75,6 +73,26 @@ int main( void ) endptr = NULL; TESTCASE( strtoull( overflow, &endptr, 0 ) == 0 ); TESTCASE( endptr == overflow ); + errno = 0; +/* long long -> 64 bit */ +#if ULLONG_MAX >> 63 == 1 + /* 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 */ +/* long long -> 128 bit */ +#elif ULLONG_MAX >> 127 == 1 + /* 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; }