[PATCH] macro: terminate the temporary VA_ARGS_FOREACH() array with a sentinel
authorFrantisek Sumsal <frantisek@sumsal.cz>
Wed, 17 Jan 2024 12:11:14 +0000 (13:11 +0100)
committerCarlos Henrique Lima Melara <charlesmelara@riseup.net>
Thu, 26 Jun 2025 00:44:53 +0000 (21:44 -0300)
commitbe8a68d070e6d7aabc03da9c256f2537e83b2ed3
tree8df4fa10e0e8c02519ea259279d218d4d87dc5b2
parent2d8c0c371b67dc7b7d308a9fef2487cc5aecebeb
[PATCH] macro: terminate the temporary VA_ARGS_FOREACH() array with a sentinel

So gcc-14 doesn't complain we're out of bounds on the last iteration:

[2092/2414] Compiling C object test-macro.p/src_test_test-macro.c.o
In file included from ../src/basic/list.h:209,
                 from ../src/basic/log.h:10,
                 from ../src/test/test-macro.c:5:
../src/test/test-macro.c: In function ‘test_FOREACH_VA_ARGS’:
../src/basic/macro.h:395:90: warning: array subscript 1 is outside array bounds of ‘uint8_t[1]’ {aka ‘unsigned char[1]’} [-Warray-bounds=]
  395 |              ((long)(_current_ - _entries_) < (long)ELEMENTSOF(_entries_)) && ({ entry = *_current_; true; }); \
../src/basic/macro.h:392:9: note: in expansion of macro ‘_VA_ARGS_FOREACH’
  392 |         _VA_ARGS_FOREACH(entry, UNIQ_T(_entries_, UNIQ), UNIQ_T(_current_, UNIQ), ##__VA_ARGS__)
      |         ^~~~~~~~~~~~~~~~
../src/test/test-macro.c:322:9: note: in expansion of macro ‘VA_ARGS_FOREACH’
  322 |         VA_ARGS_FOREACH(u8, 0) {
      |         ^~~~~~~~~~~~~~~
../src/fundamental/macro-fundamental.h:163:37: note: at offset 1 into object ‘__unique_prefix__entries_181’ of size 1
  163 | #define UNIQ_T(x, uniq) CONCATENATE(__unique_prefix_, CONCATENATE(x, uniq))
      |                                     ^~~~~~~~~~~~~~~~
../src/basic/macro.h:394:28: note: in definition of macro ‘_VA_ARGS_FOREACH’
  394 |         for (typeof(entry) _entries_[] = { __VA_ARGS__ }, *_current_ = _entries_; \
      |                            ^~~~~~~~~
../src/fundamental/macro-fundamental.h:109:27: note: in expansion of macro ‘XCONCATENATE’
  109 | #define CONCATENATE(x, y) XCONCATENATE(x, y)
      |                           ^~~~~~~~~~~~
../src/fundamental/macro-fundamental.h:163:25: note: in expansion of macro ‘CONCATENATE’
  163 | #define UNIQ_T(x, uniq) CONCATENATE(__unique_prefix_, CONCATENATE(x, uniq))
      |                         ^~~~~~~~~~~
../src/basic/macro.h:392:33: note: in expansion of macro ‘UNIQ_T’
  392 |         _VA_ARGS_FOREACH(entry, UNIQ_T(_entries_, UNIQ), UNIQ_T(_current_, UNIQ), ##__VA_ARGS__)
      |                                 ^~~~~~
../src/test/test-macro.c:322:9: note: in expansion of macro ‘VA_ARGS_FOREACH’
  322 |         VA_ARGS_FOREACH(u8, 0) {
      |         ^~~~~~~~~~~~~~~

(cherry picked from commit dc571cccd75db7be49b2aada64baf92e3a498c39)
(cherry picked from commit 0ddd788136622da3320e43aaa5005b0a68c89137)
(cherry picked from commit d44fe47f2ea48fd6da83d1748ff37f46df8b4ddd)
(cherry picked from commit 6a8d6e29cee540e06eb7dba6d5c2185a7a0ac00b)

Origin: upstream, https://github.com/systemd/systemd-stable/commit/31ba3f4ea0f472355e985c7bcca66ffc35e5735c
Forwarded: not-needed
Last-Update: 2025-06-23

Gbp-Pq: Name CVE-2025-4598-2.patch
src/basic/macro.h