RetroArch/libretro-common
pstef 790deebe42
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>
2024-10-21 14:45:23 -07:00
..
audio Fix typos (#17068) 2024-10-01 17:36:33 -07:00
cdrom Silence GCC 14 warning [-Warray-bounds=] (#17110) 2024-10-21 14:45:23 -07:00
compat Remove asserts 2023-01-09 00:51:05 +01:00
crt Squashed 'libretro-common/' changes from edffe4d147..1548bee835 2018-06-25 23:55:40 +02:00
dynamic macOS: Create App Store build (#17074) 2024-10-04 12:46:51 -07:00
encodings iC comments 2024-07-20 17:54:44 +02:00
features Fixing compiler warnings (#17001) 2024-09-14 13:11:20 -07:00
file Fix typos (#17068) 2024-10-01 17:36:33 -07:00
formats Fix typos (#17068) 2024-10-01 17:36:33 -07:00
gfx (libretro-common) Resync 2023-05-30 19:34:55 +02:00
glsym (libretro-common) Update copyright 2020-01-31 15:43:42 +01:00
hash (libretro-common) Rename rhash to lrc_hash 2020-12-28 19:55:54 +01:00
include Fix typos (#17068) 2024-10-01 17:36:33 -07:00
libco iC comments 2024-07-20 17:54:44 +02:00
lists macOS: Create App Store build (#17074) 2024-10-04 12:46:51 -07:00
media Cleanups/simplifications 2023-08-17 21:58:41 +02:00
memmap (memmap.c) Silence implicit declaration of function 'free' for PSL1GHT 2023-02-20 14:29:40 +01:00
net Fix typos (#17068) 2024-10-01 17:36:33 -07:00
playlists Minor improvements for db / playlist handling (#16060) 2023-12-30 11:45:36 -08:00
queues Rewrite libretro-common task_queue, use flags 2024-09-10 02:42:07 +02:00
rthreads Fix typos (#17068) 2024-10-01 17:36:33 -07:00
samples Fix typos (#17068) 2024-10-01 17:36:33 -07:00
streams C89 buildfix 2024-09-05 17:44:05 +02:00
string Fix typos (#17068) 2024-10-01 17:36:33 -07:00
test iC comments 2024-07-20 17:54:44 +02:00
time Remove asserts 2023-01-09 00:51:05 +01:00
utils Replace do { while (true) ; with for (;;) 2024-04-05 20:03:05 +02:00
vfs Fix typos (#17068) 2024-10-01 17:36:33 -07:00
vulkan [Vulkan] Define and implement v2 of context negotiation interface (#14890) 2023-02-04 16:51:50 +01:00
.gitignore Updates 2020-12-13 21:21:21 +01:00
Makefile.test Moving more stuff from samples to tests 2021-05-10 19:45:50 +02:00