On 5/20/25 20:20, Matthias Andree wrote:
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



I like that patch. You followed the same path as me (memcpy is ugly, nonstring is ideal but nonstandard) and did the hard yards to make it work anyway. Applied.


Cheers,

Simon.

_______________________________________________
Dnsmasq-discuss mailing list
Dnsmasq-discuss@lists.thekelleys.org.uk
https://lists.thekelleys.org.uk/cgi-bin/mailman/listinfo/dnsmasq-discuss

Reply via email to