Skip to content

Commit

Permalink
string: avoid panic strtok on null input
Browse files Browse the repository at this point in the history
The behavior of strtok when given a NULL input on the first call
is to panic on an unmapped virtual address. This commit changes it
by returning NULL instead of panic.

Signed-off-by: Daniele Ahmed <ahmeddan amazon c;0m >
  • Loading branch information
82marbag committed Jul 6, 2021
1 parent 6c96697 commit 75cec62
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions include/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,13 @@ static inline size_t strcspn(const char *s1, const char *s2) {

static inline char *strtok(char *s, const char *delim) {

static char *lasts;
static char *lasts = NULL;
int ch;

if (NULL == s)
if (s == NULL && lasts == NULL)
return NULL;

if (s == NULL)
s = lasts + 1;

do {
Expand Down

0 comments on commit 75cec62

Please sign in to comment.