diff mbox series

[1/6] Fix strtok for previous tokens being NULL

Message ID 20180517233105.8243-2-bsingharora@gmail.com
State Accepted
Headers show
Series scan build fixes | expand

Commit Message

Balbir Singh May 17, 2018, 11:31 p.m. UTC
Caught by scan-build. If the stored token nxtTok
is already NULL, don't dereference src

Signed-off-by: Balbir singh <bsingharora@gmail.com>
---
 libc/string/strtok.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/libc/string/strtok.c b/libc/string/strtok.c
index 665c08db..aa42d77e 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;