mirror of
https://github.com/fail0verflow/switch-coreboot.git
synced 2025-05-04 01:39:18 -04:00
UPSTREAM: libpayload: Fix strtok_r
This patch makes strtok_r: - handle the end of the string - handle string that contains only delimiters - do not set ptr outside of str BUG=None BRANCH=None TEST=None Signed-off-by: Jeremy Compostella <jeremy.compostella@gmail.com> Reviewed-on: https://review.coreboot.org/16524 Tested-by: build bot (Jenkins) Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org> Reviewed-by: Nico Huber <nico.h@gmx.de> Change-Id: I49925040d951dffb9c11425334674d8d498821f1 Reviewed-on: https://chromium-review.googlesource.com/383692 Commit-Ready: Furquan Shaikh <furquan@chromium.org> Tested-by: Furquan Shaikh <furquan@chromium.org> Reviewed-by: Aaron Durbin <adurbin@chromium.org>
This commit is contained in:
parent
521d3eb9c2
commit
570b248381
1 changed files with 6 additions and 2 deletions
|
@ -609,11 +609,15 @@ char* strtok_r(char *str, const char *delim, char **ptr)
|
||||||
/* skip over prefix delimiters */
|
/* skip over prefix delimiters */
|
||||||
char *start = str + strspn(str, delim);
|
char *start = str + strspn(str, delim);
|
||||||
|
|
||||||
|
if (start[0] == '\0')
|
||||||
|
return NULL;
|
||||||
|
|
||||||
/* find first delimiter character */
|
/* find first delimiter character */
|
||||||
char *end = start + strcspn(start, delim);
|
char *end = start + strcspn(start, delim);
|
||||||
end[0] = '\0';
|
*ptr = end;
|
||||||
|
if (end[0] != '\0')
|
||||||
|
*(*ptr)++ = '\0';
|
||||||
|
|
||||||
*ptr = end+1;
|
|
||||||
return start;
|
return start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue