pw-cli: fix command parsing after pw_split changes

Don't assume anything about the way the split function maintain the
state.
This commit is contained in:
Wim Taymans 2021-06-07 11:17:45 +02:00
parent 0792c690c2
commit 9a90030596

View file

@ -118,20 +118,21 @@ struct command {
static int pw_split_ip(char *str, const char *delimiter, int max_tokens, char *tokens[]) static int pw_split_ip(char *str, const char *delimiter, int max_tokens, char *tokens[])
{ {
const char *state = NULL; const char *state = NULL;
char *s; char *s, *t;
size_t len; size_t len, l2;
int n = 0; int n = 0;
s = (char *)pw_split_walk(str, delimiter, &len, &state); s = (char *)pw_split_walk(str, delimiter, &len, &state);
while (s && n + 1 < max_tokens) { while (s && n + 1 < max_tokens) {
t = (char*)pw_split_walk(str, delimiter, &l2, &state);
s[len] = '\0'; s[len] = '\0';
tokens[n++] = s; tokens[n++] = s;
s = (char*)pw_split_walk(str, delimiter, &len, &state); s = t;
} len = l2;
if (s) { }
if (s)
tokens[n++] = s; tokens[n++] = s;
} return n;
return n;
} }
static void print_properties(struct spa_dict *props, char mark, bool header) static void print_properties(struct spa_dict *props, char mark, bool header)