about summary refs log tree commit diff
path: root/string/test-strchr.c
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>2002-11-08 22:10:01 +0000
committerRoland McGrath <roland@gnu.org>2002-11-08 22:10:01 +0000
commite8c1660f7ba480c5a17103b557941fc6db7a5146 (patch)
tree71673df7864e35860bd8c7e8d2f3424fdb1dffc9 /string/test-strchr.c
parente0bc9a8d13290de5328ae49311493246f406e0bd (diff)
downloadglibc-e8c1660f7ba480c5a17103b557941fc6db7a5146.tar.gz
glibc-e8c1660f7ba480c5a17103b557941fc6db7a5146.tar.xz
glibc-e8c1660f7ba480c5a17103b557941fc6db7a5146.zip
* string/test-strchr.c (stupid_strchr): New function.
	(do_random_tests): Make sure the string is zero terminated.
	* string/test-strpbrk.c (stupid_strpbrk): New function.
	(do_random_tests): Make sure the string is zero terminated.
	* string/test-strcmp.c (stupid_strcmp): New function.
	(do_random_tests): Make sure the strings are zero terminated.
	* string/test-strspn.c (stupid_strspn): New function.
	(simple_strspn): Rename rej argument to acc.
	(do_random_tests): Make sure the string is zero terminated.
	* string/test-strcspn.c (stupid_strcspn): New function.
	* string/test-strncpy.c (stupid_strncpy): New function.
	* string/test-stpncpy.c (stupid_stpncpy): New function.
	* string/test-strncmp.c (stupid_strncmp): New function.
	(do_random_tests): Make sure the strings are zero terminated.
	* string/test-string.h (impl_t): Change test into long.
	(IMPL): Add __attribute__((aligned (sizeof (void *)))).
Diffstat (limited to 'string/test-strchr.c')
-rw-r--r--string/test-strchr.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/string/test-strchr.c b/string/test-strchr.c
index 72f7ec9557..9483e719c0 100644
--- a/string/test-strchr.c
+++ b/string/test-strchr.c
@@ -23,7 +23,9 @@
 
 typedef char *(*proto_t) (const char *, int);
 char *simple_strchr (const char *, int);
+char *stupid_strchr (const char *, int);
 
+IMPL (stupid_strchr, 0)
 IMPL (simple_strchr, 0)
 IMPL (strchr, 1)
 
@@ -36,6 +38,17 @@ simple_strchr (const char *s, int c)
   return (char *) s;
 }
 
+char *
+stupid_strchr (const char *s, int c)
+{
+  size_t n = strlen (s) + 1;
+
+  while (n--)
+    if (*s++ == (char) c)
+      return (char *) s - 1;
+  return NULL;
+}
+
 static void
 do_one_test (impl_t *impl, const char *s, int c, char *exp_res)
 {
@@ -115,15 +128,18 @@ do_random_tests (void)
     {
       align = random () & 15;
       pos = random () & 511;
+      seek_char = random () & 255;
       if (pos + align >= 511)
 	pos = 510 - align - (random () & 7);
       len = random () & 511;
-      if (pos >= len)
-	len = pos + (random () & 7);
+      if ((pos == len && seek_char)
+	  || (pos > len && (random () & 1)))
+	len = pos + 1 + (random () & 7);
       if (len + align >= 512)
         len = 511 - align - (random () & 7);
-      seek_char = random () & 255;
-      j = len + align + 64;
+      if (pos == len && seek_char)
+	len = pos + 1;
+      j = (pos > len ? pos : len) + align + 64;
       if (j > 512)
         j = 512;