neatvi
neatvi copied to clipboard
Fix -Warray-bounds warnings
I have GCC 12 on my system, and compiling neatvi triggered these warnings
cc -c -Wall -O2 reg.c
reg.c: In function ‘reg_putraw’:
reg.c:21:18: warning: array subscript [-128, 255] is outside array bounds of ‘char *[256]’ [-Warray-bounds]
21 | free(bufs[tolower(c)]);
| ~~~~^~~~~~~~~~~~
reg.c:6:14: note: while referencing ‘bufs’
6 | static char *bufs[256];
| ^~~~
reg.c:22:13: warning: array subscript [-128, 255] is outside array bounds of ‘char *[256]’ [-Warray-bounds]
22 | bufs[tolower(c)] = buf;
| ~~~~^~~~~~~~~~~~
reg.c:6:14: note: while referencing ‘bufs’
6 | static char *bufs[256];
| ^~~~
The issue is that tolower
does not necessarily return a value between 0 and 255, though this is to my understanding the implicit understanding in the code?