From 96bdb42d403b2b5beebc3b9f7a9a5d1611996f17 Mon Sep 17 00:00:00 2001 From: Matthias Andree Date: Tue, 20 May 2025 21:07:27 +0200 Subject: [PATCH] Fix GCC's -Wunterminated-string-initialization warning in edns0.c. GCC complains that writing the five-character "ODNS\0" string into a four-element char magic[4] array truncates the NUL character. The warning's rationale is that this is incompatible with C++, or maybe non-intentional. GCC 8 has added a nonstring variable attribute, clang 20.1 does not yet support this, but clang's Git head does. Add an ATTRIBUTE_NONSTRING macro, currently only defined on GCC >= 8 as __attribute__ ((nonstring)). This successfully suppresses the warning on Fedora Linux 42's default compiler. The alternative would be to replace the "ODNS" literal by {0} and instead memcpy(opt.magic, "ODNS", sizeof(opt.magic)); on the next line, which is correct, C++ compatible, but also less concise. --- src/dnsmasq.h | 6 ++++++ src/edns0.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/dnsmasq.h b/src/dnsmasq.h index 1007644..83c750d 100644 --- a/src/dnsmasq.h +++ b/src/dnsmasq.h @@ -48,6 +48,12 @@ #define ATTRIBUTE_NORETURN #endif +#if __GNUC__ + 0 >= 8 // clang 20.1.0 does not yet support this +#define ATTRIBUTE_NONSTRING __attribute__ ((nonstring)) +#else +#define ATTRIBUTE_NONSTRING +#endif + /* get these before config.h for IPv6 stuff... */ #include #include diff --git a/src/edns0.c b/src/edns0.c index e867d54..2f03291 100644 --- a/src/edns0.c +++ b/src/edns0.c @@ -494,7 +494,7 @@ int check_source(struct dns_header *header, size_t plen, unsigned char *pseudohe #define UMBRELLA_DEVICESZ sizeof(daemon->umbrella_device) struct umbrella_opt { - u8 magic[4]; + u8 magic[4] ATTRIBUTE_NONSTRING; u8 version; u8 flags; /* We have 4 possible fields since we'll never send both IPv4 and