https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77696
--- Comment #6 from David Malcolm <dmalcolm at gcc dot gnu.org> --- (In reply to David Malcolm from comment #5) > I brainstormed some ideas on making these kinds of warning easier for > the user to understand. We could use the new labeling-of-source-ranges idea from: https://gcc.gnu.org/ml/gcc-patches/2018-08/msg00901.html to print something like: demo.c: In function ‘test_2’: demo.c:6:23: warning: ‘%s’ directive writing 36 bytes into a region of size 11 [-Wformat-overflow=] 6 | sprintf (buf, "msg: %s\n", msg); | ~~~ ^~ | | | | | required space: 36 bytes | remaining capacity: 11 bytes demo.c:12:11: 12 | test_1 ("this is long enough to cause trouble"); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | required space: 36 bytes demo.c:6:3: note: ‘sprintf’ output 43 bytes into a destination of size 16 6 | sprintf (buf, "msg: %s\n", msg); | ~~~ ^~~~~~~~~ | | | | | required space: 43 bytes | size: 16 bytes (making a distinction between "size" and "remaining capacity", depending on whether the code is writing to the start of the buffer or not) Underlining "buf" requires access to its source location, which might not be available yet in the C frontend (if so, I can look at fixing that).