From 45638a63c0998137187a48a521015da35ab15a3c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 31 Jul 2020 14:40:23 +0200 Subject: [PATCH] shared/fstab-util: replace FOREACH_WORD_SEPARATOR() with open-coded loop The tricky part here is that the function is not allowed to fail in this code path. Initially, I wanted to change the return value to allow it to fail, but this cascades through all the places where fstab_test_option() and friends are used; updating all those sites would be a lot of work. And since quoting is not allowed here, a simple loop with strcspn() is easy to do. --- src/shared/fstab-util.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/shared/fstab-util.c b/src/shared/fstab-util.c index 0e1b61aa954..d883eca5c78 100644 --- a/src/shared/fstab-util.c +++ b/src/shared/fstab-util.c @@ -94,12 +94,11 @@ int fstab_filter_options(const char *opts, const char *names, /* If !ret_value and !ret_filtered, this function is not allowed to fail. */ if (!ret_filtered) { - const char *word, *state; - size_t l; + for (const char *word = opts;;) { + const char *end = word + strcspn(word, ","); - FOREACH_WORD_SEPARATOR(word, l, opts, ",", state) NULSTR_FOREACH(name, names) { - if (l < strlen(name)) + if (end < word + strlen(name)) continue; if (!strneq(word, name, strlen(name))) continue; @@ -114,12 +113,20 @@ int fstab_filter_options(const char *opts, const char *names, r = free_and_strndup(&v, eq ? x + 1 : NULL, - eq ? l - strlen(name) - 1 : 0); + eq ? end - x - 1 : 0); if (r < 0) return r; } + + break; } } + + if (*end) + word = end + 1; + else + break; + } } else { stor = strv_split(opts, ","); if (!stor) -- 2.47.3