GCC 14 is still in development, but it has a wonderful new feature in its static analyzer (-fanalyzer).

It can now draw beautiful Unicode diagrams showing exactly how you went out-of-bounds.

See https://inbox.sourceware.org/gcc-patches/[email protected]/ too.

Thank you to the wonderful David Malcolm for implementing this - who also does a tonne of work with mentoring for GCC's GSoC programme, and working on docs to help new people get into GCC: https://gcc-newbies-guide.readthedocs.io/en/latest/index.html.

@gnutools

[PATCH 0/3] Add diagram support to gcc diagnostics - David Malcolm

@thesamesam Reminds me of it being a thing where clang prints a warning but which scan-build ignores…

$ scan-build clang /tmp/foo.c -o /tmp/foo
scan-build: Using '/usr/lib/llvm/16/bin/clang-16' for static analysis
/tmp/foo.c:5:20: warning: format specifies type 'char *' but the argument has type 'char' [-Wformat]
printf("bar: %s", foo[3]);
~~ ^~~~~~
%c
/tmp/foo.c:5:20: warning: array index 3 is past the end of the array (that has type 'char[2]') [-Warray-bounds]
printf("bar: %s", foo[3]);
^ ~
/tmp/foo.c:4:2: note: array 'foo' declared here
char foo[2] = "a";
^
2 warnings generated.
scan-build: Analysis run complete.
scan-build: Removing directory '/tmp/scan-build-2023-07-14-041437-3476-1' because it contains no reports.
scan-build: No bugs found.