1
0
mirror of https://git.musl-libc.org/git/musl synced 2025-10-05 21:12:41 +02:00

fix strcasestr failing to find zero-length needle

the loop condition ending on end-of-haystack ends before a zero-length
needle can be matched, so just explicitly check it before the loop.
This commit is contained in:
Rich Felker
2025-05-16 09:10:19 -04:00
parent 23febbd3c5
commit ae3a8c93a6

View File

@@ -4,6 +4,7 @@
char *strcasestr(const char *h, const char *n)
{
size_t l = strlen(n);
if (!l) return (char *)h;
for (; *h; h++) if (!strncasecmp(h, n, l)) return (char *)h;
return 0;
}