aboutsummaryrefslogtreecommitdiff
path: root/string/test-memchr.c
diff options
context:
space:
mode:
authorRaoni Fassina Firmino <raoni@linux.ibm.com>2022-02-25 10:57:31 -0300
committerRaoni Fassina Firmino <raoni@linux.ibm.com>2022-02-25 10:57:31 -0300
commit0d6fdf9f0590f090651716b729ca5db2f1b9d620 (patch)
treeebe6dbc1ac10368fa8a781cccf52a92c7246d008 /string/test-memchr.c
parent6bbd88c2511fa62d4b682b24bfda8dcb0af39e50 (diff)
parenta79bc55e5be07d797d77b63fc0018eb515ae7049 (diff)
downloadglibc-ibm/2.30/master.zip
glibc-ibm/2.30/master.tar.gz
glibc-ibm/2.30/master.tar.bz2
Merge branch release/2.30/master into ibm/2.30/masteribm/2.30/master
Diffstat (limited to 'string/test-memchr.c')
-rw-r--r--string/test-memchr.c39
1 files changed, 36 insertions, 3 deletions
diff --git a/string/test-memchr.c b/string/test-memchr.c
index 58bb54e..32582fd 100644
--- a/string/test-memchr.c
+++ b/string/test-memchr.c
@@ -65,8 +65,8 @@ do_one_test (impl_t *impl, const CHAR *s, int c, size_t n, CHAR *exp_res)
CHAR *res = CALL (impl, s, c, n);
if (res != exp_res)
{
- error (0, 0, "Wrong result in function %s %p %p", impl->name,
- res, exp_res);
+ error (0, 0, "Wrong result in function %s (%p, %d, %zu) -> %p != %p",
+ impl->name, s, c, n, res, exp_res);
ret = 1;
return;
}
@@ -91,7 +91,7 @@ do_test (size_t align, size_t pos, size_t len, size_t n, int seek_char)
}
buf[align + len] = 0;
- if (pos < len)
+ if (pos < MIN(n, len))
{
buf[align + pos] = seek_char;
buf[align + len] = -seek_char;
@@ -108,6 +108,38 @@ do_test (size_t align, size_t pos, size_t len, size_t n, int seek_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, 751, SIZE_MAX - i, BIG_CHAR);
+ do_test (0, i, 751, i - buf_addr, BIG_CHAR);
+ do_test (0, i, 751, -buf_addr - i, BIG_CHAR);
+ do_test (0, i, 751, SIZE_MAX - buf_addr - i, BIG_CHAR);
+ do_test (0, i, 751, 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, 751, len - i, BIG_CHAR);
+ do_test (0, i, 751, len + i, BIG_CHAR);
+ do_test (0, i, 751, len - buf_addr - i, BIG_CHAR);
+ do_test (0, i, 751, len - buf_addr + i, BIG_CHAR);
+
+ do_test (0, i, 751, ~len - i, BIG_CHAR);
+ do_test (0, i, 751, ~len + i, BIG_CHAR);
+ do_test (0, i, 751, ~len - buf_addr - i, BIG_CHAR);
+ do_test (0, i, 751, ~len - buf_addr + i, BIG_CHAR);
+ }
+ }
+}
+
+static void
do_random_tests (void)
{
size_t i, j, n, align, pos, len;
@@ -221,6 +253,7 @@ test_main (void)
do_test (page_size / 2 - i, i, i, 1, 0x9B);
do_random_tests ();
+ do_overflow_tests ();
return ret;
}