Skip to content

Commit

Permalink
Fix strtok for previous tokens being NULL
Browse files Browse the repository at this point in the history
Caught by scan-build. If the stored token nxtTok
is already NULL, don't dereference src

Signed-off-by: Balbir singh <[email protected]>
Signed-off-by: Stewart Smith <[email protected]>
  • Loading branch information
bsingharora authored and stewartsmith committed May 24, 2018
1 parent 53dac89 commit ad58f8d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion libc/string/strtok.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ strtok(char *src, const char *pattern)
static char *nxtTok;
char *retVal = NULL;

if (!src)
if (!src) {
src = nxtTok;
if (!src)
return retVal;
}

while (*src) {
const char *pp = pattern;
Expand Down

0 comments on commit ad58f8d

Please sign in to comment.