diff --git a/libs/libc/string/lib_memmem.c b/libs/libc/string/lib_memmem.c index 77dbd4b357..f54ea9817c 100644 --- a/libs/libc/string/lib_memmem.c +++ b/libs/libc/string/lib_memmem.c @@ -51,12 +51,17 @@ FAR void *memmem(FAR const void *haystack, size_t haystacklen, size_t i; size_t y; + if (needlelen == 0) + { + return (void *)haystack; + } + if (needlelen > haystacklen) { return NULL; } - for (i = 0; i < haystacklen - needlelen; i++) + for (i = 0; i <= haystacklen - needlelen; i++) { y = 0; while (h[i + y] == n[y])