diff options
| author | Enji Cooper <ngie@FreeBSD.org> | 2017-02-09 21:23:41 +0000 | 
|---|---|---|
| committer | Enji Cooper <ngie@FreeBSD.org> | 2017-02-09 21:23:41 +0000 | 
| commit | 5e307759bd01dad9d65a7424eb028c43b4932f3b (patch) | |
| tree | 5fcacd65a72553a84e74f0eb00694a68c884e8d6 /lib/libc/string | |
| parent | 6266b128affa698128aa2b3042f69aa5d5ad4534 (diff) | |
Notes
Diffstat (limited to 'lib/libc/string')
| -rw-r--r-- | lib/libc/string/memmem.3 | 22 | ||||
| -rw-r--r-- | lib/libc/string/memmem.c | 6 | 
2 files changed, 17 insertions, 11 deletions
| diff --git a/lib/libc/string/memmem.3 b/lib/libc/string/memmem.3 index 73c267c14c10..fb341f44190a 100644 --- a/lib/libc/string/memmem.3 +++ b/lib/libc/string/memmem.3 @@ -26,7 +26,7 @@  .\"  .\" $FreeBSD$  .\" -.Dd August 24, 2005 +.Dd May 26, 2015  .Dt MEMMEM 3  .Os  .Sh NAME @@ -51,14 +51,12 @@ in the byte string  .Fa big .  .Sh RETURN VALUES  If -.Fa big_len -is smaller than -.Fa little_len , -if  .Fa little_len -is 0, if -.Fa big_len -is 0 or if +is zero +.Fa big +is returned (that is, an empty little is deemed to match at the beginning of +big); +if  .Fa little  occurs nowhere in  .Fa big , @@ -84,3 +82,11 @@ function first appeared in  .Sh BUGS  This function was broken in Linux libc up to and including version 5.0.9  and in GNU libc prior to version 2.1. +Prior to +.Fx 11.0 +.Nm +returned +.Dv NULL +when +.Fa little_len +equals 0. diff --git a/lib/libc/string/memmem.c b/lib/libc/string/memmem.c index 72e6517e7b4d..3fd05dfdbbc9 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) | 
