summaryrefslogtreecommitdiff
path: root/tests/unistr/test-u-strstr.h
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2024-03-03 19:11:32 +0100
committerJörg Frings-Fürst <debian@jff.email>2024-03-03 19:11:32 +0100
commit00893e79fc62966067af1a106567db96bd170338 (patch)
tree52b35cd0b42ca28e62a2ffbecade2e13dd8332cf /tests/unistr/test-u-strstr.h
parent26112352a774737e1ce5580c93654a26c1e82b39 (diff)
New upstream version 1.2upstream/1.2
Diffstat (limited to 'tests/unistr/test-u-strstr.h')
-rw-r--r--tests/unistr/test-u-strstr.h40
1 files changed, 39 insertions, 1 deletions
diff --git a/tests/unistr/test-u-strstr.h b/tests/unistr/test-u-strstr.h
index d53183e1..36783cdf 100644
--- a/tests/unistr/test-u-strstr.h
+++ b/tests/unistr/test-u-strstr.h
@@ -1,5 +1,5 @@
/* Test of uN_strstr() functions.
- Copyright (C) 2004, 2007-2022 Free Software Foundation, Inc.
+ Copyright (C) 2004, 2007-2024 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -207,4 +207,42 @@ test_u_strstr (void)
free (needle);
free (haystack);
}
+
+ /* Test case from Yves Bastide.
+ <https://www.openwall.com/lists/musl/2014/04/18/2> */
+ {
+ const UNIT input[] =
+ { 'p', 'l', 'a', 'y', 'i', 'n', 'g', ' ', 'p', 'l', 'a', 'y', ' ', 'p',
+ 'l', 'a', 'y', ' ', 'p', 'l', 'a', 'y', ' ', 'a', 'l', 'w', 'a', 'y',
+ 's', 0
+ };
+ const UNIT needle[] =
+ { 'p', 'l', 'a', 'y', ' ', 'p', 'l', 'a', 'y', ' ', 'p', 'l', 'a', 'y',
+ 0
+ };
+ const UNIT *result = U_STRSTR (input, needle);
+ ASSERT (result == input + 8);
+ }
+
+ /* Test long needles. */
+ {
+ size_t m = 1024;
+ UNIT *haystack = (UNIT *) malloc ((2 * m + 1) * sizeof (UNIT));
+ UNIT *needle = (UNIT *) malloc ((m + 1) * sizeof (UNIT));
+ if (haystack != NULL && needle != NULL)
+ {
+ const UNIT *p;
+ haystack[0] = 'x';
+ U_SET (haystack + 1, ' ', m - 1);
+ U_SET (haystack + m, 'x', m);
+ haystack[2 * m] = '\0';
+ U_SET (needle, 'x', m);
+ needle[m] = '\0';
+ p = U_STRSTR (haystack, needle);
+ ASSERT (p);
+ ASSERT (p - haystack == m);
+ }
+ free (needle);
+ free (haystack);
+ }
}