aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--string/tester.c51
2 files changed, 51 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 7c7a9721d3..56f2786124 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,9 @@
1999-04-30 Ulrich Drepper <drepper@cygnus.com>
- * sysdeps/i386/strchrnul.S: Fix bugs which let to wrong results in
+ * string/tester.c (test_strchrnul): New function.
+ (test_memset): Test one more special case.
+
+ * sysdeps/i386/strchrnul.S: Fix bugs which lead to wrong results in
25% of all cases.
* sysdeps/i386/i486/bits/string.h: Replace __uintXX_t types with
diff --git a/string/tester.c b/string/tester.c
index d874fe3379..96c7aa219c 100644
--- a/string/tester.c
+++ b/string/tester.c
@@ -409,6 +409,40 @@ test_strchr (void)
}
void
+test_strchrnul (void)
+{
+ const char *os;
+ it = "strchrnul";
+ cp = strchrnul ((os = "abcd"), 'z');
+ check (*cp == '\0', 1); /* Not found. */
+ check (cp == os + 4, 2);
+ (void) strcpy (one, "abcd");
+ check (strchrnul (one, 'c') == one+2, 3); /* Basic test. */
+ check (strchrnul (one, 'd') == one+3, 4); /* End of string. */
+ check (strchrnul (one, 'a') == one, 5); /* Beginning. */
+ check (strchrnul (one, '\0') == one+4, 6); /* Finding NUL. */
+ (void) strcpy (one, "ababa");
+ check (strchrnul (one, 'b') == one+1, 7); /* Finding first. */
+ (void) strcpy (one, "");
+ check (strchrnul (one, 'b') == one, 8); /* Empty string. */
+ check (strchrnul (one, '\0') == one, 9); /* NUL in empty string. */
+ {
+ char buf[4096];
+ int i;
+ char *p;
+ for (i=0; i < 0x100; i++)
+ {
+ p = (char *) ((unsigned long int) (buf + 0xff) & ~0xff) + i;
+ strcpy (p, "OK");
+ strcpy (p+3, "BAD/WRONG");
+ cp = strchrnul (p, '/');
+ check (*cp == '\0', 9+2*i);
+ check (cp == p+2, 10+2*i);
+ }
+ }
+}
+
+void
test_index (void)
{
it = "index";
@@ -906,6 +940,8 @@ test_memccpy (void)
void
test_memset (void)
{
+ int i;
+
it = "memset";
(void) strcpy(one, "abcdefgh");
check(memset(one+1, 'x', 3) == one+1, 1); /* Return value. */
@@ -921,12 +957,16 @@ test_memset (void)
(void) memset(one+2, 010045, 1);
equal(one, "ax\045xe", 6); /* Unsigned char convert. */
+ /* Non-8bit fill character. */
+ memset (one, 0x101, sizeof (one));
+ for (i = 0; i < sizeof (one); ++i)
+ check (one[i] == '\01', 7);
+
/* Test for more complex versions of memset, for all alignments and
lengths up to 256. This test takes a little while, perhaps it should
- be made weaker? */
+ be made weaker? */
{
char data[512];
- int i;
int j;
int k;
int c;
@@ -938,7 +978,7 @@ test_memset (void)
for (j = 0; j < 256; j++)
for (i = 0; i < 256; i++)
{
- memset(data+i,c,j);
+ memset (data + i, c, j);
for (k = 0; k < i; k++)
if (data[k] != 'x')
goto fail;
@@ -954,7 +994,7 @@ test_memset (void)
continue;
fail:
- check(0,7+i+j*256+(c != 0)*256*256);
+ check (0, 8 + i + j * 256 + (c != 0) * 256 * 256);
}
}
}
@@ -1056,6 +1096,9 @@ main (void)
/* strchr. */
test_strchr ();
+ /* strchrnul. */
+ test_strchrnul ();
+
/* index - just like strchr. */
test_index ();