]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Darwin regtest: memmem returns NULL if either length is 0.
authorPaul Floyd <pjfloyd@wanadoo.fr>
Mon, 25 Dec 2023 08:00:26 +0000 (09:00 +0100)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Mon, 25 Dec 2023 08:00:26 +0000 (09:00 +0100)
memcheck/tests/memmem.c

index 7cefafcc6525bf239d2f4dfc9cdf6a7bbcd4213c..41dc0fa3db713eb64c438f237e4d0238171cb02c 100644 (file)
@@ -2,6 +2,7 @@
 #include <assert.h>
 #include <string.h>
 #include <stdlib.h>
+#include "../../config.h"
 
 /* mallocs an mem block and fills it with A. A needs to be a zero
    terminated string. The A string chars, minus the terminating zero
@@ -23,7 +24,17 @@ main ()
 
   haystack = create_mem ("a");
   needle = create_mem ("a");
+#if defined(VGO_darwin)
+  /*
+   * macOS manpage says
+   * If big_len is smaller than little_len, if little_len is 0, if big_len is 0 or if
+   * little occurs nowhere in big, NULL is returned; otherwise a pointer to the first
+   * character of the first occurrence of little is returned.
+   */
+  assert (memmem (haystack, 0, needle, 0) == NULL);
+#else
   assert (memmem (haystack, 0, needle, 0) == haystack);
+#endif
   assert (memmem (haystack, 1, needle, 0) == haystack);
   assert (memmem (haystack, 0, needle, 1) == NULL);
   assert (memmem (haystack, 1, needle, 1) == haystack);