From: Dan Streetman Date: Thu, 2 Feb 2023 20:58:10 +0000 (-0500) Subject: [PATCH] basic/macro: add macro to iterate variadic args X-Git-Tag: archive/raspbian/247.3-7+rpi1+deb11u7^2~7 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=2d8c0c371b67dc7b7d308a9fef2487cc5aecebeb;p=systemd.git [PATCH] basic/macro: add macro to iterate variadic args (cherry picked from commit e179f2d89c9f0c951636d74de00136b4075cd1ac) (cherry picked from commit cd4f43bf378ff33ce5cfeacd96f7f3726603bddc) Origin: upstream, https://github.com/systemd/systemd-stable/commit/c288a3aafdf11cd93eb7a21e4d587c6fc218a29c Forwarded: not-needed Last-Update: 2025-06-23 Gbp-Pq: Name CVE-2025-4598-1.patch --- diff --git a/src/basic/macro.h b/src/basic/macro.h index 27825537..ee835419 100644 --- a/src/basic/macro.h +++ b/src/basic/macro.h @@ -654,4 +654,13 @@ static inline size_t size_add(size_t x, size_t y) { return y >= SIZE_MAX - x ? SIZE_MAX : x + y; } +/* Iterate through each variadic arg. All must be the same type as 'entry' or must be implicitly + * convertable. The iteration variable 'entry' must already be defined. */ +#define VA_ARGS_FOREACH(entry, ...) \ + _VA_ARGS_FOREACH(entry, UNIQ_T(_entries_, UNIQ), UNIQ_T(_current_, UNIQ), ##__VA_ARGS__) +#define _VA_ARGS_FOREACH(entry, _entries_, _current_, ...) \ + for (typeof(entry) _entries_[] = { __VA_ARGS__ }, *_current_ = _entries_; \ + ((long)(_current_ - _entries_) < (long)ELEMENTSOF(_entries_)) && ({ entry = *_current_; true; }); \ + _current_++) + #include "log.h"