From 71dda51708c0f9cafff337fda0a02322981dc48c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 16 Jan 2019 00:13:38 +0100 Subject: (backport) strv: rework FOREACH_STRING() macro So it's apparently problematic that we use STRV_MAKE() (i.e. a compound initializer) outside of the {} block we use it in (and that includes outside of the ({}) block, too). Hence, let's rework the macro to not need that. This also makes the macro shorter, which is definitely a good and more readable. Moreover, it will now complain if the iterator is a "char*" instead of a "const char*", which is good too. Fixes: #11394 Change-Id: Ibc21cdd5583c3b6a079b8691bbac5e076819432a --- src/basic/strv.h | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/basic/strv.h b/src/basic/strv.h index 385ad17779..172b99ee89 100644 --- a/src/basic/strv.h +++ b/src/basic/strv.h @@ -150,17 +150,10 @@ void strv_print(char **l); _x && strv_contains(STRV_MAKE(__VA_ARGS__), _x); \ }) -#define FOREACH_STRING(x, ...) \ - for (char **_l = ({ \ - char **_ll = STRV_MAKE(__VA_ARGS__); \ - x = _ll ? _ll[0] : NULL; \ - _ll; \ - }); \ - _l && *_l; \ - x = ({ \ - _l ++; \ - _l[0]; \ - })) +#define FOREACH_STRING(x, y, ...) \ + for (char **_l = STRV_MAKE(({ x = y; }), ##__VA_ARGS__); \ + x; \ + x = *(++_l)) char **strv_reverse(char **l); char **strv_shell_escape(char **l, const char *bad); -- cgit v1.2.3