[Bug middle-end/77696] Confusing wording for -Wformat-overflow

dmalcolm at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Sep 13 13:14:00 GMT 2018


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77696

--- Comment #8 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.

Getting really fancy, we could emit an ASCII art visualization to
(hopefully) make the buffer overflow crystal-clear (with an option to
disable it):

demo.c:6:3: note: buffer overflow [-fdiagnostics-show-buffer-overflow]
  snprintf of "%s" from:
                        |+---+---+ ... +---+---+|+---+---+ ... +---+---+|
                        ||  0|  1|     |  9| 10||| 11| 12|     | 41| 42||
                        ||'t'|'h'|     |'o'|'n'|||'g'|' '|     |'e'|NUL||
                        |+---+---+ ... +---+---+|+---+---+ ... +---+---+|
                        vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
                        |<---   ok          --->|<--     overflow    -->|
                        |                       |                       |
  to 'buf':
  |                     |                       |
  ++---+---+---+---+---+|+---+---+ ... +---+---+|
  ||  0|  1|  2|  3|   4||5  |  6|     | 14| 15||
  ||'m'|'s'|'g'|':'|' '|||'t'|'h'|     |'o'|'n'||
  ++---+---+---+---+---+|+---+---+ ... +---+---+|
                        |                       |

(thus showing the buffer content where it's known, eliding the middle
when it goes above 5 elements)

The parts on the right-hand side ("overflow" etc) could be colorized in
red.


More information about the Gcc-bugs mailing list