From ad58f8da1d4fbd45abf163514a9643a14e1636ee Mon Sep 17 00:00:00 2001 From: Balbir singh Date: Fri, 18 May 2018 09:31:00 +1000 Subject: Fix strtok for previous tokens being NULL Caught by scan-build. If the stored token nxtTok is already NULL, don't dereference src Signed-off-by: Balbir singh Signed-off-by: Stewart Smith --- libc/string/strtok.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'libc/string') diff --git a/libc/string/strtok.c b/libc/string/strtok.c index 665c08d..aa42d77 100644 --- a/libc/string/strtok.c +++ b/libc/string/strtok.c @@ -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; -- cgit v1.1