mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-22 22:03:43 +03:00
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.
This commit is contained in:
parent
0e8d185938
commit
45638a63c0
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user