From 3b681f2138c11dea630e0373fe929541a2c75264 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Thu, 3 Jun 2021 16:18:17 +0200 Subject: [PATCH] pipewire: utils: pw_split_walk(): skip leading runs of chars in `delimiter` Previously, if the string started with any of the characters in delimiter, the first returned string would've been an empty string. This is in contrast with the fact that otherwise `pw_split_walk()` skips empty fields. E.g. "::field1::field2" with ":" as `delimiter` would have resulted in * "" * "field1" * "field2". Adjust the function to skip leading runs of characters in `delimiter` by calling `strspn()` first. --- src/pipewire/utils.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pipewire/utils.c b/src/pipewire/utils.c index 2cf1f9733..aad3289c8 100644 --- a/src/pipewire/utils.c +++ b/src/pipewire/utils.c @@ -44,13 +44,12 @@ const char *pw_split_walk(const char *str, const char *delimiter, size_t * len, { const char *s = *state ? *state : str; + s += strspn(s, delimiter); if (*s == '\0') return NULL; *len = strcspn(s, delimiter); - *state = s + *len; - *state += strspn(*state, delimiter); return s; }