summaryrefslogtreecommitdiffstats
path: root/src/basic/macro.h
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2023-03-09 05:14:12 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2023-03-09 08:41:43 +0100
commitb9872fe1ddb61a7f930c652887c04e2f82b43be4 (patch)
tree834e0cfe31149b7075ebebd2edd80fc1166cd8ed /src/basic/macro.h
parentMerge pull request #26698 from ldv-alt/udevadm-verify (diff)
downloadsystemd-b9872fe1ddb61a7f930c652887c04e2f82b43be4.tar.xz
systemd-b9872fe1ddb61a7f930c652887c04e2f82b43be4.zip
macro: support the case that the number of elements has const qualifier
Follow-up for 5716c27e1f52d2aba9dd02916c01d6271d9d0b16. Addresses https://github.com/systemd/systemd/pull/26303#issuecomment-1460712007.
Diffstat (limited to 'src/basic/macro.h')
-rw-r--r--src/basic/macro.h10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/basic/macro.h b/src/basic/macro.h
index 3de319d880..63344f8d97 100644
--- a/src/basic/macro.h
+++ b/src/basic/macro.h
@@ -297,12 +297,14 @@ static inline int __coverity_check_and_return__(int condition) {
p != (typeof(p)) POINTER_MAX; \
p = *(++_l))
-#define _FOREACH_ARRAY(i, array, num, m, s) \
- for (typeof(num) m = (num); m > 0; m = 0) \
- for (typeof(array[0]) *s = (array), *i = s; s && i < s + m; i++)
+#define _FOREACH_ARRAY(i, array, num, m, end) \
+ for (typeof(array[0]) *i = (array), *end = ({ \
+ typeof(num) m = (num); \
+ (i && m > 0) ? i + m : NULL; \
+ }); end && i < end; i++)
#define FOREACH_ARRAY(i, array, num) \
- _FOREACH_ARRAY(i, array, num, UNIQ_T(m, UNIQ), UNIQ_T(s, UNIQ))
+ _FOREACH_ARRAY(i, array, num, UNIQ_T(m, UNIQ), UNIQ_T(end, UNIQ))
#define DEFINE_TRIVIAL_DESTRUCTOR(name, type, func) \
static inline void name(type *p) { \