MINOR: compiler: add __nonstring macro
authorValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Mon, 31 Mar 2025 09:47:45 +0000 (11:47 +0200)
committerWilliam Lallemand <wlallemand@haproxy.com>
Wed, 10 Sep 2025 14:13:31 +0000 (16:13 +0200)
commit77cd566756233ea6618bfa851073dd16c9a04f9c
treee33c0dbb1697ca68d9f93877d51a2a54a2c5f0bb
parentcb1a35e73fbd6151dbef3301377144344057a44a
MINOR: compiler: add __nonstring macro

GCC 15 throws the following warning on fixed-size char arrays if they do not
contain terminated NUL:

src/tools.c:2041:25: error: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (17 chars into 16 available) [-Werror=unterminated-string-initialization]
 2041 | const char hextab[16] = "0123456789ABCDEF";

We are using a couple of such definitions for some constants. Converting them
to flexible arrays, like: hextab[] = "0123456789ABCDEF" may have consequences,
as enlarged arrays won't fit anymore where they were possibly located due to
the memory alignement constraints.

GCC adds 'nonstring' variable attribute for such char arrays, but clang and
other compilers don't have it. Let's wrap 'nonstring' with our
__nonstring macro, which will test if the compiler supports this attribute.

This fixes the issue #2910.

(cherry picked from commit b3038614696fee43b6eaa826f47f273a8619690d)
[wla: should be backported to every stable branches]
Signed-off-by: William Lallemand <wlallemand@haproxy.com>
(cherry picked from commit d4234b3c32b79b8dffd70f22c1eb3ba39541acb3)
Signed-off-by: William Lallemand <wlallemand@haproxy.com>
include/haproxy/compiler.h
src/tools.c