diff options
author | emaste <emaste@FreeBSD.org> | 2015-05-26 21:16:07 +0000 |
---|---|---|
committer | emaste <emaste@FreeBSD.org> | 2015-05-26 21:16:07 +0000 |
commit | d45a21328b20ce30a629a8ae4a01e8e3434e7000 (patch) | |
tree | 85b8aed82ce3e7f57eb4b089de73b2bf3c567b5f /lib/libc/string/memmem.c | |
parent | 2f93a7904f7b9a0fb327e9a909adad7c177df8e5 (diff) | |
download | FreeBSD-src-d45a21328b20ce30a629a8ae4a01e8e3434e7000.zip FreeBSD-src-d45a21328b20ce30a629a8ae4a01e8e3434e7000.tar.gz |
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.
Reviewed by: bapt, ngie
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D2657
Diffstat (limited to 'lib/libc/string/memmem.c')
-rw-r--r-- | lib/libc/string/memmem.c | 6 |
1 files changed, 3 insertions, 3 deletions
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) |