New warning from NetBSD 9.0
Achim Gratz
Stromeko at nexgo.de
Wed Feb 19 20:37:54 UTC 2020
Hal Murray via devel writes:
> NetBSD just released version 9.0. It now generates this warning:
>
> ../../ntpd/ntp_control.c:1476:34: warning: '%s' directive output may be
> truncated writing up to 255 bytes into a region of size between 0 and 255
> [-Wformat-truncation=]
>
> char str[256];
>
> snprintf(str, sizeof(str), "%s/%s", utsnamebuf.sysname,
> utsnamebuf.release);
>
> Has anybody seen this before and/or know how to fix it?
You are supposed to either use a format that has a bounded size below or at
the limit you are allowing snprintf or check the return value from
snprintf to see if it truncated the result. The snprintf function returns the
number of chars it would have delivered if it didn't have to truncate
(and negative values for errors).
I believe gcc just checks whether you consume the return value somehow
and stops emitting the warning when you do.
Regards,
Achim.
--
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+
Factory and User Sound Singles for Waldorf Blofeld:
http://Synth.Stromeko.net/Downloads.html#WaldorfSounds
More information about the devel
mailing list