https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77696
--- Comment #15 from David Malcolm <dmalcolm at gcc dot gnu.org> --- (In reply to David Malcolm from comment #14) Some random UI ideas (brainstorming in Emacs, so no idea if these are *good* ideas): warning: buffer overflow: writing 9-110 bytes into a buffer with capacity 80 [-Wformat-overflow=] 7 | __builtin_sprintf (buf, "/%s/%s-%i.tmp", tmpdir, fname, num); | ~~~ ~~~^~~~~~~~~~ | | | | | writing 9...110 bytes | capacity: 80 bytes note: details 7 | __builtin_sprintf (buf, "/%s/%s-%i.tmp", tmpdir, fname, num); | ~~~ ab~cd~ef~g~~~h | | || || || | | | | || || || | 1 byte (NUL terminator) | | || || || 4 bytes (".tmp") | | || || |1...16 bytes ("%i" on 'num') | | || || 1 byte ("-") | | || |0-8 bytes ("%s" on 'fname') | | || 1 byte ("/") | | |0-79 bytes ("%s" on 'tmpdir') | | 1 byte ("/") | capacity: 80 bytes note: layout [-fsome-option-enabling-this] (with alternating colorization to better distinguish all those ranges and labels) |+---+--------------+----+-------------+-----+-----------+------+------+ start @||0 |1 |1-80|2-81 |10-89|11-90 |12-106|16-110| size:|| 1| 0 - 79 | 1| 8| 1| 1-16???| 4| 1| ||"/"|%s on 'tmpdir'| "/"|%s on 'fname'| "-" |%i on 'num'|".tmp"| NUL | |+---+--------------+----+-------------+-----+-----------+------+------+ or with a vertical orientation: note: layout [-fsome-option-enabling-this] +----------------+-----------+--------+---------------+ |element |starting at| size|cumulative size| +----------------+-----------+--------+---------------+ |"/" | 0 | 1 | 1 | |"%s" on 'tmpdir'| 1 | 0 - 79 | 1 - 80 | |"/" | 1 - 80 | 1 | 2 - 81 | |"%s" on 'fname' | 2 - 81 | 0 - 7 | 2 - 88 | |"-" | 2 - 88 | 1 | 3 - 89 | |"%i" on 'num' | 3 - 89 | 1- 16 | 4 - 105 | |".tmp" | 4 - 105 | 4 | 8 - 109 | |NUL terminator | 8 - 109 | 1 | 9 - 110 | +----------------+-----------+--------+---------------+ (I've probably got some of the numbers wrong above, but hopefully you get the idea of where I'm going with this). Maybe some kind of highlight to show where we can exceed the buffer capacity. I like calling out the NUL terminator explicitly (as it's so easy to get wrong), and putting "buffer overflow" upfront in the text of the warning, as I did above.