Page MenuHomeFreeBSD

memmem(3): empty little string matches the beginning of big
ClosedPublic

Authored by emaste on May 26 2015, 6:19 PM.
Tags
None
Referenced Files
F151858670: D2657.id.diff
Sat, Apr 11, 4:00 AM
F151824621: D2657.diff
Fri, Apr 10, 10:11 PM
Unknown Object (File)
Thu, Apr 9, 9:55 PM
Unknown Object (File)
Thu, Apr 9, 5:31 PM
Unknown Object (File)
Mon, Apr 6, 3:57 PM
Unknown Object (File)
Sat, Apr 4, 10:01 AM
Unknown Object (File)
Wed, Apr 1, 5:34 PM
Unknown Object (File)
Mon, Mar 30, 9:26 AM
Subscribers
None

Details

Summary

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.

Test Plan

kyua test lib/libc/string/memmem:memmem_basic

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

emaste retitled this revision from to memmem(3): empty little string matches the beginning of big.
emaste updated this object.
emaste edited the test plan for this revision. (Show Details)
emaste added reviewers: ngie, bapt, jilles.
ngie edited edge metadata.

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;
}
This revision is now accepted and ready to land.May 26 2015, 6:43 PM

For reference, NetBSD, OpenBSD and musl share the "new" behaviour (with this change) with glibc
OS X and DragonFly have the "old" behaviour

emaste edited edge metadata.

Update cast as in OpenBSD

This revision now requires review to proceed.May 26 2015, 6:55 PM
emaste edited edge metadata.

update man page too

bapt edited edge metadata.
This revision is now accepted and ready to land.May 26 2015, 8:06 PM
This revision was automatically updated to reflect the committed changes.