aboutsummaryrefslogtreecommitdiff
path: root/string/test-strnlen.c
diff options
context:
space:
mode:
Diffstat (limited to 'string/test-strnlen.c')
-rw-r--r--string/test-strnlen.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/string/test-strnlen.c b/string/test-strnlen.c
index f7d0896..027b9ad 100644
--- a/string/test-strnlen.c
+++ b/string/test-strnlen.c
@@ -90,6 +90,38 @@ do_test (size_t align, size_t len, size_t maxlen, int max_char)
}
static void
+do_overflow_tests (void)
+{
+ size_t i, j, len;
+ const size_t one = 1;
+ uintptr_t buf_addr = (uintptr_t) buf1;
+
+ for (i = 0; i < 750; ++i)
+ {
+ do_test (0, i, SIZE_MAX - i, BIG_CHAR);
+ do_test (0, i, i - buf_addr, BIG_CHAR);
+ do_test (0, i, -buf_addr - i, BIG_CHAR);
+ do_test (0, i, SIZE_MAX - buf_addr - i, BIG_CHAR);
+ do_test (0, i, SIZE_MAX - buf_addr + i, BIG_CHAR);
+
+ len = 0;
+ for (j = 8 * sizeof(size_t) - 1; j ; --j)
+ {
+ len |= one << j;
+ do_test (0, i, len - i, BIG_CHAR);
+ do_test (0, i, len + i, BIG_CHAR);
+ do_test (0, i, len - buf_addr - i, BIG_CHAR);
+ do_test (0, i, len - buf_addr + i, BIG_CHAR);
+
+ do_test (0, i, ~len - i, BIG_CHAR);
+ do_test (0, i, ~len + i, BIG_CHAR);
+ do_test (0, i, ~len - buf_addr - i, BIG_CHAR);
+ do_test (0, i, ~len - buf_addr + i, BIG_CHAR);
+ }
+ }
+}
+
+static void
do_random_tests (void)
{
size_t i, j, n, align, len;
@@ -274,6 +306,7 @@ test_main (void)
do_random_tests ();
do_page_tests ();
do_page_2_tests ();
+ do_overflow_tests ();
return ret;
}