[coreboot-gerrit] New patch to review for coreboot: libpayload: Fix strtok_r

Jérémy Compostella (jeremy.compostella@gmail.com) gerrit at coreboot.org
Wed Sep 7 14:21:45 CEST 2016


Jérémy Compostella (jeremy.compostella at gmail.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/16524

-gerrit

commit 93c10d42fcc6d7b0b300fe9a31db8eb16d14090c
Author: Jeremy Compostella <jeremy.compostella at intel.com>
Date:   Wed Sep 7 14:09:34 2016 +0200

    libpayload: Fix strtok_r
    
    This patch makes strtok_r:
    - handle the end of the string
    - do not set ptr outside of str
    
    Change-Id: I49925040d951dffb9c11425334674d8d498821f1
    Signed-off-by: Jeremy Compostella <jeremy.compostella at gmail.com>
---
 payloads/libpayload/libc/string.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/payloads/libpayload/libc/string.c b/payloads/libpayload/libc/string.c
index 9985749..ac346ed 100644
--- a/payloads/libpayload/libc/string.c
+++ b/payloads/libpayload/libc/string.c
@@ -606,14 +606,18 @@ char* strtok_r(char *str, const char *delim, char **ptr)
 	if (str == NULL)
 		str = *ptr;
 
+	if (str[0] == '\0')
+		return NULL;
+
 	/* skip over prefix delimiters */
 	char *start = str + strspn(str, delim);
 
 	/* find first delimiter character */
 	char *end = start + strcspn(start, delim);
-	end[0] = '\0';
+	*ptr = end;
+	if (end[0] != '\0')
+		*(*ptr)++ = '\0';
 
-	*ptr = end+1;
 	return start;
 }
 



More information about the coreboot-gerrit mailing list