summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2025-05-16 09:10:19 -0400
committerRich Felker <dalias@aerifal.cx>2025-05-16 09:11:14 -0400
commitae3a8c93a663b553e65f096498937083dad210d2 (patch)
treef30256d8ada8b92a9a48daf7676565d6ee593ac4
parent23febbd3c5d6b4e367faee4f39b8e8c3b95ab588 (diff)
downloadmusl-master.tar.gz
fix strcasestr failing to find zero-length needleHEADmaster
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.
-rw-r--r--src/string/strcasestr.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/string/strcasestr.c b/src/string/strcasestr.c
index af109f36..dc598bc3 100644
--- a/src/string/strcasestr.c
+++ b/src/string/strcasestr.c
@@ -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;
}