]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
strv: Fixup STRV_FOREACH_PAIR macro
authorAdrian Vovk <adrianvovk@gmail.com>
Wed, 4 Sep 2024 03:45:08 +0000 (23:45 -0400)
committerAdrian Vovk <adrianvovk@gmail.com>
Tue, 17 Sep 2024 18:06:26 +0000 (14:06 -0400)
The macro didn't properly parenthesize a caller-controlled argument.
For example: `STRV_FOREACH_PAIR(a, b, something ?: something_else)`
would expand to `typeof(*something ?: something_else)`, which would
cause compile failures

src/basic/strv.h

index bd90305e63e097bdd098908b8943ae6d1bc23c74..d38d5bf538456a6042afd7ebe471523d15dc4a74 100644 (file)
@@ -153,7 +153,7 @@ bool strv_overlap(char * const *a, char * const *b) _pure_;
         _STRV_FOREACH_BACKWARDS(s, l, UNIQ_T(h, UNIQ), UNIQ_T(i, UNIQ))
 
 #define _STRV_FOREACH_PAIR(x, y, l, i)                          \
-        for (typeof(*l) *x, *y, *i = (l);                       \
+        for (typeof(*(l)) *x, *y, *i = (l);                     \
              i && *(x = i) && *(y = i + 1);                     \
              i += 2)