浏览代码

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.
Rich Felker 1 周之前
父节点
当前提交
ae3a8c93a6
共有 1 个文件被更改,包括 1 次插入0 次删除
  1. 1 0
      src/string/strcasestr.c

+ 1 - 0
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;
 }