diff options
author | Ulrich Drepper <drepper@gmail.com> | 2011-07-21 06:56:25 -0400 |
---|---|---|
committer | Ulrich Drepper <drepper@gmail.com> | 2011-07-21 06:56:25 -0400 |
commit | a65c0b7a322d0084672bc7fc4b51af8f2a054d57 (patch) | |
tree | cd35d8a81e3df23c373623b3ccb9aa792bb0d15a | |
parent | 90bb2039e93c6b7e95531cf9a9dfc23bbb50f860 (diff) | |
download | glibc-a65c0b7a322d0084672bc7fc4b51af8f2a054d57.tar.gz glibc-a65c0b7a322d0084672bc7fc4b51af8f2a054d57.tar.xz glibc-a65c0b7a322d0084672bc7fc4b51af8f2a054d57.zip |
Add more tests for strcat and strncat.
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | string/tester.c | 93 |
2 files changed, 96 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog index a76483ad2a..17096fb456 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-07-21 Ulrich Drepper <drepper@gmail.com> + + * string/tester.c (test_strcat): Add tests for different alignments + of source and destination. + (test_strncat): Likewise. + 2011-07-20 Ulrich Drepper <drepper@gmail.com> [BZ #12852] diff --git a/string/tester.c b/string/tester.c index 01da0465da..a86249de7d 100644 --- a/string/tester.c +++ b/string/tester.c @@ -1,5 +1,6 @@ /* Tester for string functions. - Copyright (C) 1995-2001, 2003, 2005, 2008, 2010 Free Software Foundation, Inc. + Copyright (C) 1995-2001,2003,2005,2008,2010,2011 + Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -46,7 +47,7 @@ check (int thing, int number) { if (!thing) { - printf("%s flunked test %d\n", it, number); + printf ("%s flunked test %d\n", it, number); ++errors; } } @@ -55,7 +56,7 @@ check (int thing, int number) static void equal (const char *a, const char *b, int number) { - check(a != NULL && b != NULL && STREQ (a, b), number); + check (a != NULL && b != NULL && STREQ (a, b), number); } char one[50]; @@ -302,6 +303,48 @@ test_strcat (void) (void) strcpy (one, ""); (void) strcat (one, "cd"); equal (one, "cd", 9); + + int ntest = 10; + char buf1[80] __attribute__ ((aligned (16))); + char buf2[32] __attribute__ ((aligned (16))); + for (size_t n1 = 0; n1 < 16; ++n1) + for (size_t n2 = 0; n2 < 16; ++n2) + for (size_t n3 = 0; n3 < 32; ++n3) + { + size_t olderrors = errors; + + memset (buf1, 'b', sizeof (buf1)); + + memset (buf1 + n2, 'a', n3); + buf1[n2 + n3] = '\0'; + strcpy (buf2 + n1, "123"); + + check (strcat (buf1 + n2, buf2 + n1) == buf1 + n2, ntest); + if (errors == olderrors) + for (size_t i = 0; i < sizeof (buf1); ++i) + { + if (i < n2) + check (buf1[i] == 'b', ntest); + else if (i < n2 + n3) + check (buf1[i] == 'a', ntest); + else if (i < n2 + n3 + 3) + check (buf1[i] == "123"[i - (n2 + n3)], ntest); + else if (i == n2 + n3 + 3) + check (buf1[i] == '\0', ntest); + else + check (buf1[i] == 'b', ntest); + + if (errors != olderrors) + { + printf ("n1=%zu, n2=%zu, n3=%zu, buf1=%02hhx", + n1, n2, n3, buf1[0]); + for (size_t j = 1; j < sizeof (buf1); ++j) + printf (",%02hhx", buf1[j]); + putchar_unlocked ('\n'); + break; + } + } + } } static void @@ -347,6 +390,50 @@ test_strncat (void) (void) strncat (one, "ij", (size_t)-1); /* set sign bit in count */ equal (one, "abcdghij", 13); + + int ntest = 14; + char buf1[80] __attribute__ ((aligned (16))); + char buf2[32] __attribute__ ((aligned (16))); + for (size_t n1 = 0; n1 < 16; ++n1) + for (size_t n2 = 0; n2 < 16; ++n2) + for (size_t n3 = 0; n3 < 32; ++n3) + for (size_t n4 = 0; n4 < 16; ++n4) + { + size_t olderrors = errors; + + memset (buf1, 'b', sizeof (buf1)); + + memset (buf1 + n2, 'a', n3); + buf1[n2 + n3] = '\0'; + strcpy (buf2 + n1, "123"); + + check (strncat (buf1 + n2, buf2 + n1, ~((size_t) 0) - n4) + == buf1 + n2, ntest); + if (errors == olderrors) + for (size_t i = 0; i < sizeof (buf1); ++i) + { + if (i < n2) + check (buf1[i] == 'b', ntest); + else if (i < n2 + n3) + check (buf1[i] == 'a', ntest); + else if (i < n2 + n3 + 3) + check (buf1[i] == "123"[i - (n2 + n3)], ntest); + else if (i == n2 + n3 + 3) + check (buf1[i] == '\0', ntest); + else + check (buf1[i] == 'b', ntest); + + if (errors != olderrors) + { + printf ("n1=%zu, n2=%zu, n3=%zu, n4=%zu, buf1=%02hhx", + n1, n2, n3, n4, buf1[0]); + for (size_t j = 1; j < sizeof (buf1); ++j) + printf (",%02hhx", buf1[j]); + putchar_unlocked ('\n'); + break; + } + } + } } static void |