mirror of
https://git.musl-libc.org/git/musl
synced 2025-01-10 00:32:27 +03:00
fix search past the end of haystack in memmem
to optimize the search, memchr is used to find the first occurrence of the first character of the needle in the haystack before switching to a search for the full needle. however, the number of characters skipped by this first step were not subtracted from the haystack length, causing memmem to search past the end of the haystack.
This commit is contained in:
parent
e94d069286
commit
6fbdeff0e5
@ -139,6 +139,7 @@ void *memmem(const void *h0, size_t k, const void *n0, size_t l)
|
||||
/* Use faster algorithms for short needles */
|
||||
h = memchr(h0, *n, k);
|
||||
if (!h || l==1) return (void *)h;
|
||||
k -= h - (const unsigned char *)h0;
|
||||
if (l==2) return twobyte_memmem(h, k, n);
|
||||
if (l==3) return threebyte_memmem(h, k, n);
|
||||
if (l==4) return fourbyte_memmem(h, k, n);
|
||||
|
Loading…
Reference in New Issue
Block a user