diff options
author | Simon Glass <sjg@chromium.org> | 2024-07-30 08:39:36 -0600 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2024-08-07 08:49:10 -0600 |
commit | 947aafdebc9f64f12e8aa6ae7f60758f04bd1540 (patch) | |
tree | 96db92d2ce7d1cf42b431472cf92e525421af6e2 /lib/strto.c | |
parent | 04894f5ad53cab0ee03eb3bc1cc1682e22f5dd1b (diff) |
lib: Handle a special case with str_to_list()
The current implementation can return an extra result at the end when
the string ends with a space. Fix this by adding a special case.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'lib/strto.c')
-rw-r--r-- | lib/strto.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/strto.c b/lib/strto.c index 5157332d6c1..f83ac67c666 100644 --- a/lib/strto.c +++ b/lib/strto.c @@ -236,12 +236,14 @@ const char **str_to_list(const char *instr) return NULL; /* count the number of space-separated strings */ - for (count = *str != '\0', p = str; *p; p++) { + for (count = 0, p = str; *p; p++) { if (*p == ' ') { count++; *p = '\0'; } } + if (p != str && p[-1]) + count++; /* allocate the pointer array, allowing for a NULL terminator */ ptr = calloc(count + 1, sizeof(char *)); |