summaryrefslogtreecommitdiff
path: root/src/basic/strv.h
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-08-26 19:18:15 +0200
committerLennart Poettering <lennart@poettering.net>2016-10-07 20:14:38 +0200
commit4a39c774196f1a694477432f845e8bd62efee245 (patch)
tree7ebdfbdab40660fcf8087b967eaa5d6598d85584 /src/basic/strv.h
parentf767d3de652ec18c84ff0b99b1c4430269501e51 (diff)
downloadsystemd-4a39c774196f1a694477432f845e8bd62efee245.tar.gz
strv: fix STRV_FOREACH_BACKWARDS() to be a single statement only
Let's make sure people invoking STRV_FOREACH_BACKWARDS() as a single statement of an if statement don't fall into a trap, and find the tail for the list via strv_length().
Diffstat (limited to 'src/basic/strv.h')
-rw-r--r--src/basic/strv.h11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/basic/strv.h b/src/basic/strv.h
index fec2597db0..385ad17779 100644
--- a/src/basic/strv.h
+++ b/src/basic/strv.h
@@ -96,10 +96,13 @@ bool strv_overlap(char **a, char **b) _pure_;
#define STRV_FOREACH(s, l) \
for ((s) = (l); (s) && *(s); (s)++)
-#define STRV_FOREACH_BACKWARDS(s, l) \
- STRV_FOREACH(s, l) \
- ; \
- for ((s)--; (l) && ((s) >= (l)); (s)--)
+#define STRV_FOREACH_BACKWARDS(s, l) \
+ for (s = ({ \
+ char **_l = l; \
+ _l ? _l + strv_length(_l) - 1U : NULL; \
+ }); \
+ (l) && ((s) >= (l)); \
+ (s)--)
#define STRV_FOREACH_PAIR(x, y, l) \
for ((x) = (l), (y) = (x+1); (x) && *(x) && *(y); (x) += 2, (y) = (x + 1))