From a7022cbffe1ecbf64f5010813bbfad9220560101 Mon Sep 17 00:00:00 2001 From: ngie Date: Thu, 9 Feb 2017 21:23:41 +0000 Subject: MFC r283584: Relnotes: yes r283584 (by emaste): memmem(3): empty little string matches the beginning of the big string This function originated in glibc, and this matches their behaviour (and NetBSD, OpenBSD, and musl). An empty big string (arg "l") is handled by the existing l_len < s_len test. --- lib/libc/string/memmem.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/libc/string/memmem.c') diff --git a/lib/libc/string/memmem.c b/lib/libc/string/memmem.c index 72e6517..3fd05df 100644 --- a/lib/libc/string/memmem.c +++ b/lib/libc/string/memmem.c @@ -42,9 +42,9 @@ memmem(const void *l, size_t l_len, const void *s, size_t s_len) const char *cl = (const char *)l; const char *cs = (const char *)s; - /* we need something to compare */ - if (l_len == 0 || s_len == 0) - return NULL; + /* empty "s" matches the beginning of "l" */ + if (s_len == 0) + return (void *)cl; /* "s" must be smaller or equal to "l" */ if (l_len < s_len) -- cgit v1.1