Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Silence GCC 14 warning [-Warray-bounds=] (#17110)
* Silence GCC 14 warning [-Warray-bounds=] GCC reports a couple of warnings like this example: libretro-common/cdrom/cdrom.c:395:14: warning: array subscript 6 is outside array bounds of 'unsigned char[6]' [-Warray-bounds=] 395 | cmd[6] = cmd[3]; | ~~~~~~~^~~~~~~~ libretro-common/cdrom/cdrom.c: In function 'cdrom_unlock': libretro-common/cdrom/cdrom.c:1268:18: note: at offset 6 into object 'cdb' of size 6 1268 | unsigned char cdb[] = {0x1E, 0, 0, 0, 0x2, 0}; The static analysis heuristic doesn't consider the fact that the writes to cmd[6] and later only happen under the condition that `if (cmd[0] == 0xBE || cmd[0] == 0xB9)` and that in all of those cases the array passed is wide enough. So this is a false positive. Nevertheless, there seems to be an easy way to silence the warning without disabling it: just require all arrays passed to be at least 9 bytes long and explicitly set the size of those arrays that have been shorter to 9. * Work around the requirement of C89 I used a C99 construct, but this is easy to work around with a run-time check. * Restore the check for non-null cmd It was obsoleted in a previous version, but is needed back now. --------- Co-authored-by: pstef <3462925+pstef@users.noreply.github.com>
- Loading branch information