This function originated in glibc, and this matches the behaviour of their implementation.
An empty big string (arg "l") is handled by the existing l_len < s_len test.
Differential D2657
memmem(3): empty little string matches the beginning of big emaste on May 26 2015, 6:19 PM. Authored by Tags None Referenced Files
Subscribers None
Details
This function originated in glibc, and this matches the behaviour of their implementation. An empty big string (arg "l") is handled by the existing l_len < s_len test. kyua test lib/libc/string/memmem:memmem_basic
Diff Detail
Event TimelineComment Actions LGTM: $ cat /etc/redhat-release Fedora release 20 (Heisenbug) $ ./test_memmem ; echo $? 0 $ cat test_memmem.c #define _GNU_SOURCE #include <assert.h> #include <string.h> char p0[] = ""; int lp0 = 0; char b0[] = ""; int lb0 = 0; char b2[] = "0123456789"; int lb2 = 10; int main(void) { assert(memmem(b2, lb2, p0, lp0) == b2); assert(memmem(b0, lb0, p0, lp0) == b0); return 0; } Comment Actions For reference, NetBSD, OpenBSD and musl share the "new" behaviour (with this change) with glibc |