diff options
author | joseph <joseph@7b3dc134-2b1b-0410-93df-9e9f96275f8d> | 2013-07-02 00:11:45 +0000 |
---|---|---|
committer | joseph <joseph@7b3dc134-2b1b-0410-93df-9e9f96275f8d> | 2013-07-02 00:11:45 +0000 |
commit | 94ba134cf6431dad0aaece271a16761bc793d490 (patch) | |
tree | b2b77be695fb5add3d132101bf25f2be915f3139 /libc/string/test-memcmp.c | |
parent | f42fd2771adb82cb5f34ba9e80a607975111da48 (diff) |
Merge changes between r23363 and r23421 from /fsf/trunk.
git-svn-id: svn://svn.eglibc.org/trunk@23422 7b3dc134-2b1b-0410-93df-9e9f96275f8d
Diffstat (limited to 'libc/string/test-memcmp.c')
-rw-r--r-- | libc/string/test-memcmp.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/libc/string/test-memcmp.c b/libc/string/test-memcmp.c index b30e34d0e..0420cd0b7 100644 --- a/libc/string/test-memcmp.c +++ b/libc/string/test-memcmp.c @@ -448,6 +448,29 @@ check1 (void) } } +/* This test checks that memcmp doesn't overrun buffers. */ +static void +check2 (void) +{ + size_t max_length = page_size / sizeof (CHAR); + + /* Initialize buf2 to the same values as buf1. The bug requires the + last compared byte to be different. */ + memcpy (buf2, buf1, page_size); + ((char *) buf2)[page_size - 1] ^= 0x11; + + for (size_t length = 1; length < max_length; length++) + { + CHAR *s1 = (CHAR *) buf1 + max_length - length; + CHAR *s2 = (CHAR *) buf2 + max_length - length; + + const int exp_result = SIMPLE_MEMCMP (s1, s2, length); + + FOR_EACH_IMPL (impl, 0) + check_result (impl, s1, s2, length, exp_result); + } +} + int test_main (void) { @@ -456,6 +479,7 @@ test_main (void) test_init (); check1 (); + check2 (); printf ("%23s", ""); FOR_EACH_IMPL (impl, 0) |