From b6c53c9648d208ece06b4812e5f8786c9948cc20 Mon Sep 17 00:00:00 2001 From: lukileczo Date: Tue, 23 Jan 2024 14:21:40 +0100 Subject: [PATCH] string/strstr: handle empty special case JIRA: RTOS-743 --- string/string.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/string/string.c b/string/string.c index 539a7ca6..714c12c7 100644 --- a/string/string.c +++ b/string/string.c @@ -327,6 +327,10 @@ char *strstr(const char *s1, const char *s2) { const char *p1, *p2; + if (*s2 == '\0') { + return (char *)s1; + } + for (; *s1; ++s1) { for (p1 = s1, p2 = s2; *p2 && *p1 && *p1 == *p2; ++p1, ++p2) ;