]> pd.if.org Git - pdclib/blobdiff - functions/inttypes/strtoumax.c
SVN properties cleanup.
[pdclib] / functions / inttypes / strtoumax.c
old mode 100755 (executable)
new mode 100644 (file)
index 063e7ab..9c9833e
@@ -75,6 +75,26 @@ int main( void )
     endptr = NULL;
     TESTCASE( strtoumax( overflow, &endptr, 0 ) == 0 );
     TESTCASE( endptr == overflow );
+    errno = 0;
+/* uintmax_t -> long long -> 64 bit */
+#if UINTMAX_MAX >> 63 == 1
+    /* 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 */
+/* uintmax_t -> long long -> 128 bit */
+#elif UINTMAX_MAX >> 127 == 1
+    /* 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;
 }