https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78913
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |diagnostic Status|UNCONFIRMED |WAITING Last reconfirmed| |2016-12-23 Ever confirmed|0 |1 --- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> --- The warning in this case is based on the knowledge that the longest string that fits into a.path is 511 characters, which given the format string of "%s/_\n" would result in 515 characters being written in to the the 512 element array (and characters past the 511th being truncated). The expectation is that the call be written like so: snprintf (out.path, sizeof (struct buffer), "%.508s/_\n", a.path); I would at some point like to add fixit hints with this suggestion (I'm tracking the feature request in bug 77831). One other possibility I considered is adding a new option (distinct from -Wformat-length) to control the snprintf truncation case. Yet another possible "feature" is to distinguish the case when the snprintf return value is used vs ignored (the latter likely being a bug). Though that wouldn't change anything in this case. Let me know your thoughts.