richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
be0c12
From 3539a72c260063713e4ecba17966ba9a768d8af9 Mon Sep 17 00:00:00 2001
be0c12
From: Lennart Poettering <lennart@poettering.net>
be0c12
Date: Wed, 16 Jan 2019 00:13:38 +0100
be0c12
Subject: [PATCH] strv: rework FOREACH_STRING() macro
be0c12
be0c12
So it's apparently problematic that we use STRV_MAKE() (i.e. a compound
be0c12
initializer) outside of the {} block we use it in (and that includes
be0c12
outside of the ({}) block, too). Hence, let's rework the macro to not
be0c12
need that.
be0c12
be0c12
This also makes the macro shorter, which is definitely a good and more
be0c12
readable. Moreover, it will now complain if the iterator is a "char*"
be0c12
instead of a "const char*", which is good too.
be0c12
be0c12
Fixes: #11394
be0c12
(cherry picked from commit 66a64081f82dfad90f2f9394a477820a2e3e6510)
be0c12
be0c12
Related: #2017033
be0c12
---
be0c12
 src/basic/strv.h | 15 ++++-----------
be0c12
 1 file changed, 4 insertions(+), 11 deletions(-)
be0c12
be0c12
diff --git a/src/basic/strv.h b/src/basic/strv.h
be0c12
index c1e4c973b6..a09d76706d 100644
be0c12
--- a/src/basic/strv.h
be0c12
+++ b/src/basic/strv.h
be0c12
@@ -148,17 +148,10 @@ void strv_print(char **l);
be0c12
                 _found;                                         \
be0c12
         })
be0c12
 
be0c12
-#define FOREACH_STRING(x, ...)                               \
be0c12
-        for (char **_l = ({                                  \
be0c12
-                char **_ll = STRV_MAKE(__VA_ARGS__);         \
be0c12
-                x = _ll ? _ll[0] : NULL;                     \
be0c12
-                _ll;                                         \
be0c12
-        });                                                  \
be0c12
-        _l && *_l;                                           \
be0c12
-        x = ({                                               \
be0c12
-                _l ++;                                       \
be0c12
-                _l[0];                                       \
be0c12
-        }))
be0c12
+#define FOREACH_STRING(x, y, ...)                                       \
be0c12
+        for (char **_l = STRV_MAKE(({ x = y; }), ##__VA_ARGS__);        \
be0c12
+             x;                                                         \
be0c12
+             x = *(++_l))
be0c12
 
be0c12
 char **strv_reverse(char **l);
be0c12
 char **strv_shell_escape(char **l, const char *bad);