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

Balbir singh bsingharora at gmail.com
Fri May 18 09:31:00 AEST 2018


Caught by scan-build. If the stored token nxtTok
is already NULL, don't dereference src

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

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;
-- 
2.17.0



More information about the Skiboot mailing list