memmem, strstr, strcasestr: fix bug with long periodic needle
[gnulib.git] / tests / test-memmem.c
index 3a21213..da0d1be 100644 (file)
@@ -89,6 +89,25 @@ main (int argc, char *argv[])
     ASSERT (result == input);
   }
 
+  /* Check that a long periodic needle does not cause false positives.  */
+  {
+    const char input[] = ("F_BD_CE_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD"
+                          "_C3_88_20_EF_BF_BD_EF_BF_BD_EF_BF_BD"
+                          "_C3_A7_20_EF_BF_BD");
+    const char need[] = "_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD";
+    const char *result = memmem (input, strlen (input), need, strlen (need));
+    ASSERT (result == NULL);
+  }
+  {
+    const char input[] = ("F_BD_CE_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD"
+                          "_C3_88_20_EF_BF_BD_EF_BF_BD_EF_BF_BD"
+                          "_C3_A7_20_EF_BF_BD_DA_B5_C2_A6_20"
+                          "_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD");
+    const char need[] = "_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD";
+    const char *result = memmem (input, strlen (input), need, strlen (need));
+    ASSERT (result == input + 115);
+  }
+
   /* Check that a very long haystack is handled quickly if the needle is
      short and occurs near the beginning.  */
   {