Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silence GCC 14 warning [-Warray-bounds=] #17110

Merged
merged 3 commits into from
Oct 21, 2024
Merged

Commits on Oct 21, 2024

  1. 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.
    pstef committed Oct 21, 2024
    Configuration menu
    Copy the full SHA
    4f7e057 View commit details
    Browse the repository at this point in the history
  2. Work around the requirement of C89

    I used a C99 construct, but this is easy to work around
    with a run-time check.
    pstef committed Oct 21, 2024
    Configuration menu
    Copy the full SHA
    b577034 View commit details
    Browse the repository at this point in the history
  3. Restore the check for non-null cmd

    It was obsoleted in a previous version, but is needed back now.
    pstef committed Oct 21, 2024
    Configuration menu
    Copy the full SHA
    15c881b View commit details
    Browse the repository at this point in the history