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, Jun 7, 12:33 AM
Unknown Object (File)
May 24 2024, 8:08 AM
Unknown Object (File)
Apr 26 2024, 1:58 AM
Unknown Object (File)
Apr 26 2024, 1:55 AM
Unknown Object (File)
Apr 26 2024, 1:55 AM
Unknown Object (File)
Apr 26 2024, 1:55 AM
Unknown Object (File)
Apr 26 2024, 1:54 AM
Unknown Object (File)
Apr 25 2024, 7:24 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.