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
Unknown Object (File)
Fri, Dec 27, 2:05 AM
Unknown Object (File)
Sun, Dec 22, 11:12 PM
Unknown Object (File)
Sat, Dec 21, 1:07 AM
Unknown Object (File)
Fri, Dec 20, 6:12 AM
Unknown Object (File)
Thu, Dec 12, 6:18 AM
Unknown Object (File)
Dec 7 2024, 5:50 AM
Unknown Object (File)
Nov 29 2024, 11:30 PM
Unknown Object (File)
Nov 22 2024, 9:27 PM
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.