Fix build - NULL pointer check

This commit is contained in:
cpq 2023-02-28 17:55:25 +00:00
parent 4c356bc368
commit 20c5da6e55
2 changed files with 2 additions and 0 deletions

View File

@ -4930,6 +4930,7 @@ const char *mg_strstr(const struct mg_str haystack,
const struct mg_str needle) {
size_t i;
if (needle.len > haystack.len) return NULL;
if (needle.len == 0) return haystack.ptr;
for (i = 0; i <= haystack.len - needle.len; i++) {
if (memcmp(haystack.ptr + i, needle.ptr, needle.len) == 0) {
return haystack.ptr + i;

View File

@ -74,6 +74,7 @@ const char *mg_strstr(const struct mg_str haystack,
const struct mg_str needle) {
size_t i;
if (needle.len > haystack.len) return NULL;
if (needle.len == 0) return haystack.ptr;
for (i = 0; i <= haystack.len - needle.len; i++) {
if (memcmp(haystack.ptr + i, needle.ptr, needle.len) == 0) {
return haystack.ptr + i;