https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97628
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Ever confirmed|0 |1 Blocks| |85741 Known to fail| |10.2.0, 11.0, 9.3.0 Last reconfirmed| |2020-10-29 --- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> --- Confirmed with GCC 9 through 11. The -Wformat-truncation and -Wformat-overflow warnings rely on the range propagation engine in GCC (EVRP) to determine the ranges of integer arguments. The note they print shows the range they obtain from it. In this case the range is less than optimal. GCC 11 adds a new range engine (the Ranger) capable of computing more accurate ranges on demand. The Ranger hasn't been integrated with the strlen/sprintf pass yet but once it is, I expect this warning to go away. In the meantime, explicitly asserting just before the snprintf that the argument is in the expected range avoids the warning: if (num < 10) __builtin_unreachable (); snprintf (buf, 10, "%d", num); as does casting the argument to an unsigned type. Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85741 [Bug 85741] [meta-bug] bogus/missing -Wformat-overflow