[Bug c/79082] -Wformat-truncation inconsistent behaviour
sirl at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Jan 19 18:22:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79082
--- Comment #4 from Franz Sirl <sirl at gcc dot gnu.org> ---
Hmm, %hhd is not usable on some of our platforms and also only really helpful
with exact %x outputs:
snprintf(buffer, 3, "%02hhx", val);
What about:
snprintf(buffer, 4, "%03hx", val & 0xfff);
Here the 'h' modifier doesn't help at all and also in my eyes 'val & 0xfff' or
'abs(val % 100)' would be much more natural range limiters for warning
suppression. It's a pity there isn't at least a minimum "arguments-only-VRP"
even at -O0.
Can't we have another level or two for -Wformat-truncation that only warns when
VRP is active?
Note that I believe that
snprintf(buffer, 3, "%2d", (val < 0) ? -(val % 100) : val % 100);
shouldn't warn when VRP is active. Seems to be a minor deficiency in VRP.
More information about the Gcc-bugs
mailing list