Skip to content

Commit

Permalink
string/strstr: handle empty special case
Browse files Browse the repository at this point in the history
JIRA: RTOS-743
  • Loading branch information
lukileczo committed Jan 23, 2024
1 parent ed74176 commit b6c53c9
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions string/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
;
Expand Down

0 comments on commit b6c53c9

Please sign in to comment.