about summary refs log tree commit diff
path: root/string
diff options
context:
space:
mode:
Diffstat (limited to 'string')
-rw-r--r--string/test-stpncpy.c4
-rw-r--r--string/test-string.h3
-rw-r--r--string/test-strncmp.c2
-rw-r--r--string/test-strncpy.c4
-rw-r--r--string/test-strpbrk.c8
-rw-r--r--string/test-strspn.c8
6 files changed, 22 insertions, 7 deletions
diff --git a/string/test-stpncpy.c b/string/test-stpncpy.c
index 5bcb1ddef4..8784588645 100644
--- a/string/test-stpncpy.c
+++ b/string/test-stpncpy.c
@@ -47,8 +47,8 @@ simple_stpncpy (char *dst, const char *src, size_t n)
 char *
 stupid_stpncpy (char *dst, const char *src, size_t n)
 {
-  size_t ns = strlen (src);
-  size_t i, nc = n < ns ? n : ns;
+  size_t nc = strnlen (src, n);
+  size_t i;
 
   for (i = 0; i < nc; ++i)
     dst[i] = src[i];
diff --git a/string/test-string.h b/string/test-string.h
index ae7fc3440a..c131f19de7 100644
--- a/string/test-string.h
+++ b/string/test-string.h
@@ -143,6 +143,9 @@ test_init (void)
       printf ("Setting seed to 0x%x\n", seed);
       srandom (seed);
     }
+
+  memset (buf1, 0xa5, page_size);
+  memset (buf2, 0x5a, page_size);
 }
 
 #endif
diff --git a/string/test-strncmp.c b/string/test-strncmp.c
index 8881909646..2c49e576d6 100644
--- a/string/test-strncmp.c
+++ b/string/test-strncmp.c
@@ -42,7 +42,7 @@ simple_strncmp (const char *s1, const char *s2, size_t n)
 int
 stupid_strncmp (const char *s1, const char *s2, size_t n)
 {
-  size_t ns1 = strlen (s1) + 1, ns2 = strlen (s2) + 1;
+  size_t ns1 = strnlen (s1, n) + 1, ns2 = strnlen (s2, n) + 1;
   int ret = 0;
 
   n = ns1 < n ? ns1 : n;
diff --git a/string/test-strncpy.c b/string/test-strncpy.c
index 11ff30eebf..7820b61158 100644
--- a/string/test-strncpy.c
+++ b/string/test-strncpy.c
@@ -47,8 +47,8 @@ simple_strncpy (char *dst, const char *src, size_t n)
 char *
 stupid_strncpy (char *dst, const char *src, size_t n)
 {
-  size_t ns = strlen (src);
-  size_t i, nc = n < ns ? n : ns;
+  size_t nc = strnlen (src, n);
+  size_t i;
 
   for (i = 0; i < nc; ++i)
     dst[i] = src[i];
diff --git a/string/test-strpbrk.c b/string/test-strpbrk.c
index 77cf56dd16..a920c00041 100644
--- a/string/test-strpbrk.c
+++ b/string/test-strpbrk.c
@@ -97,7 +97,7 @@ do_test (size_t align, size_t pos, size_t len)
   char *rej, *s;
 
   align &= 7;
-  if (align + pos >= page_size || len > 240)
+  if (align + pos + 10 >= page_size || len > 240)
     return;
 
   rej = buf2 + (random () & 255);
@@ -127,6 +127,12 @@ do_test (size_t align, size_t pos, size_t len)
 	}
     }
   s[pos] = rej[random () % (len + 1)];
+  if (s[pos])
+    {
+      for (i = pos + 1; i < pos + 10; ++i)
+	s[i] = random () & 255;
+      s[i] = '\0';
+    }
   result = STRPBRK_RESULT (s, pos);
 
   if (HP_TIMING_AVAIL)
diff --git a/string/test-strspn.c b/string/test-strspn.c
index 4a6475295e..8701687d4b 100644
--- a/string/test-strspn.c
+++ b/string/test-strspn.c
@@ -99,7 +99,7 @@ do_test (size_t align, size_t pos, size_t len)
   char *acc, *s;
 
   align &= 7;
-  if (align + pos >= page_size || len > 240 || ! len)
+  if (align + pos + 10 >= page_size || len > 240 || ! len)
     return;
 
   acc = buf2 + (random () & 255);
@@ -120,6 +120,12 @@ do_test (size_t align, size_t pos, size_t len)
   s[pos] = random () & 255;
   if (strchr (acc, s[pos]))
     s[pos] = '\0';
+  else
+    {
+      for (i = pos + 1; i < pos + 10; ++i)
+	s[i] = random () & 255;
+      s[i] = '\0';
+    }
 
   if (HP_TIMING_AVAIL)
     printf ("Length %4zd, alignment %2zd, acc len %2zd:", pos, align, len);