[Dnsmasq-discuss] suggestion re the umbrella_opt GCC15 initializer-string truncation warning (was: Three v2.92test8 findings (one regression from d1008215 made 2025 May 14))
Matthias Andree
matthias.andree at gmx.de
Tue May 20 19:20:50 UTC 2025
Am 19.05.25 um 21:56 schrieb Simon Kelley:
>
>
> On 5/16/25 17:46, Matthias Andree wrote:
>> finding #3: GCC15 is a bit overzealous with its warnings and displays
>> this on what seems reasonable code to me:
>>
>>> edns0.c:In function 'add_umbrella_opt':
>>> edns0.c:512:30:warning: initializer-string for array of 'unsigned
>>> char' truncates NUL terminator but destination lacks 'nonstring'
>>> attribute (5 chars into 4 available) [-Wunterminated-string-
>>> initialization]
>>> 512 | struct umbrella_opt opt = {{"ODNS"}, UMBRELLA_VERSION, 0,
>>> {0}};
>>> | ^
>>
>
> It seems reasonable code to me too, and a any fix would be much more
> ugly. Ignoring.
Simon,
While we agree that the code is reasonable, I figured out the warning is
(1) because sometimes such initializations apparently are undesirable
and too many people seem to have used footguns, and (2) more
importantly, they are permitted by C standards but invalid C++ code,
hence the warning. In the GCC bug tracker, there has been some
discussion on whether the warning should be limited to C or -fpermissive
C++ code or if used with -Wc++-compat. dnsmasq would require quite a bit
of variable renaming to become well-formed C++ in addition to C. "class"
and "new" are reserved words, for example.
I am offering a patch (attached & against master == v2.92test9) that's a
touch less ugly than what we may have had thought early, feel free to
take it if you find it acceptable. The key here is that GCC >= 8 has a
nonstring variable attribute which we can attach inside the structure,
and that quenches the warnings.
Feel free to continue ignoring the underlying issue and this patch. Its
description contains an alternative involving memcpy() that I tested but
my take is it might be aesthetically less palatable for you. (I didn't
run bloatchecks but rely on the optimizer treating fixed
compile-time-constant-length memcpy specially). -- Of course I can also
apply -Wno-unterminated-string-initialization on the dnsmasq versions
I'll package.
Cheers,
Matthias
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fix-GCC-s-Wunterminated-string-initialization-warnin.patch
Type: text/x-patch
Size: 1950 bytes
Desc: not available
URL: <http://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/attachments/20250520/5e0530c0/attachment.bin>
More information about the Dnsmasq-discuss
mailing list