summary refs log tree commit diff
path: root/string
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2012-10-14 00:05:10 -0700
committerH.J. Lu <hjl.tools@gmail.com>2012-10-19 01:20:12 -0700
commit38c78296506316d4f84df2bd095f5efe6804308e (patch)
treefaa28e2f0a0f6290dc467a3b4c8c4176588ef887 /string
parentb44d43a01620a29c0ee7b25fe994adb22fa511d5 (diff)
downloadglibc-38c78296506316d4f84df2bd095f5efe6804308e.tar.gz
glibc-38c78296506316d4f84df2bd095f5efe6804308e.tar.xz
glibc-38c78296506316d4f84df2bd095f5efe6804308e.zip
Add a testcase for BZ #14716
Diffstat (limited to 'string')
-rw-r--r--string/test-memmem.c35
1 files changed, 32 insertions, 3 deletions
diff --git a/string/test-memmem.c b/string/test-memmem.c
index 4076029d1b..5f32a0e791 100644
--- a/string/test-memmem.c
+++ b/string/test-memmem.c
@@ -56,8 +56,8 @@ simple_memmem (const void *haystack, size_t haystack_len, const void *needle,
   return NULL;
 }
 
-static void
-do_one_test (impl_t *impl, const void *haystack, size_t haystack_len,
+static int
+check_result (impl_t *impl, const void *haystack, size_t haystack_len,
 	     const void *needle, size_t needle_len, const void *expected)
 {
   void *res;
@@ -68,9 +68,20 @@ do_one_test (impl_t *impl, const void *haystack, size_t haystack_len,
       error (0, 0, "Wrong result in function %s %p %p", impl->name,
 	     res, expected);
       ret = 1;
-      return;
+      return -1;
     }
 
+  return 0;
+}
+
+static void
+do_one_test (impl_t *impl, const void *haystack, size_t haystack_len,
+	     const void *needle, size_t needle_len, const void *expected)
+{
+  if (check_result (impl, haystack, haystack_len, needle, needle_len,
+		    expected) < 0)
+    return;
+
   if (HP_TIMING_AVAIL)
     {
       hp_timing_t start __attribute ((unused));
@@ -145,6 +156,22 @@ do_random_tests (void)
     }
 }
 
+static void
+check1 (void)
+{
+
+  const char search_buf_data[5] = { 0x56, 0x34, 0x12, 0x78, 0x78 };
+  const char pattern[2] = { 0x78, 0x56 };
+  void *search_buf = (void *) buf1 + page_size - sizeof search_buf_data;
+  void *exp_result;
+
+  memcpy (search_buf, search_buf_data, sizeof search_buf_data);
+  exp_result = simple_memmem (search_buf, sizeof search_buf_data,
+			      pattern, sizeof pattern);
+  FOR_EACH_IMPL (impl, 0)
+    check_result (impl, search_buf, sizeof search_buf_data,
+		  pattern, sizeof pattern, exp_result);
+}
 
 static const char *const strs[] =
   {
@@ -161,6 +188,8 @@ test_main (void)
 
   test_init ();
 
+  check1 ();
+
   printf ("%23s", "");
   FOR_EACH_IMPL (impl, 0)
     printf ("\t%s", impl->name);