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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions libretro-common/cdrom/cdrom.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
#define CDROM_CUE_TRACK_BYTES 107
#define CDROM_MAX_SENSE_BYTES 16
#define CDROM_MAX_RETRIES 10
#define CDROM_MIN_BUFSIZE 9

typedef enum
{
Expand Down Expand Up @@ -383,7 +384,7 @@ static int cdrom_send_command(libretro_vfs_implementation_file *stream, CDROM_CM
size_t copied_bytes = 0;
bool read_cd = false;

if (!cmd || cmd_len == 0)
if (!cmd || cmd_len == 0 || cmd_len < CDROM_MIN_BUFSIZE)
return 1;

if (cmd[0] == 0xBE || cmd[0] == 0xB9)
Expand Down Expand Up @@ -665,7 +666,7 @@ static const char* get_profile(unsigned short profile)

int cdrom_get_sense(libretro_vfs_implementation_file *stream, unsigned char *sense, size_t len)
{
unsigned char cdb[] = {0x3, 0, 0, 0, 0xFC, 0};
unsigned char cdb[CDROM_MIN_BUFSIZE] = {0x3, 0, 0, 0, 0xFC, 0};
unsigned char buf[0xFC] = {0};
int rv = cdrom_send_command(stream, DIRECTION_IN, buf, sizeof(buf), cdb, sizeof(cdb), 0);

Expand Down Expand Up @@ -1161,7 +1162,7 @@ int cdrom_write_cue(libretro_vfs_implementation_file *stream, char **out_buf, si
int cdrom_get_inquiry(libretro_vfs_implementation_file *stream, char *model, int len, bool *is_cdrom)
{
/* MMC Command: INQUIRY */
unsigned char cdb[] = {0x12, 0, 0, 0, 0xff, 0};
unsigned char cdb[CDROM_MIN_BUFSIZE] = {0x12, 0, 0, 0, 0xff, 0};
unsigned char buf[256] = {0};
int rv = cdrom_send_command(stream, DIRECTION_IN, buf, sizeof(buf), cdb, sizeof(cdb), 0);
bool cdrom = false;
Expand Down Expand Up @@ -1248,7 +1249,7 @@ int cdrom_read(libretro_vfs_implementation_file *stream, cdrom_group_timeouts_t
int cdrom_stop(libretro_vfs_implementation_file *stream)
{
/* MMC Command: START STOP UNIT */
unsigned char cdb[] = {0x1B, 0, 0, 0, 0x0, 0};
unsigned char cdb[CDROM_MIN_BUFSIZE] = {0x1B, 0, 0, 0, 0x0, 0};
int rv = cdrom_send_command(stream, DIRECTION_NONE, NULL, 0, cdb, sizeof(cdb), 0);

#ifdef CDROM_DEBUG
Expand All @@ -1265,7 +1266,7 @@ int cdrom_stop(libretro_vfs_implementation_file *stream)
int cdrom_unlock(libretro_vfs_implementation_file *stream)
{
/* MMC Command: PREVENT ALLOW MEDIUM REMOVAL */
unsigned char cdb[] = {0x1E, 0, 0, 0, 0x2, 0};
unsigned char cdb[CDROM_MIN_BUFSIZE] = {0x1E, 0, 0, 0, 0x2, 0};
int rv = cdrom_send_command(stream, DIRECTION_NONE, NULL, 0, cdb, sizeof(cdb), 0);

#ifdef CDROM_DEBUG
Expand Down Expand Up @@ -1294,7 +1295,7 @@ int cdrom_unlock(libretro_vfs_implementation_file *stream)
int cdrom_open_tray(libretro_vfs_implementation_file *stream)
{
/* MMC Command: START STOP UNIT */
unsigned char cdb[] = {0x1B, 0, 0, 0, 0x2, 0};
unsigned char cdb[CDROM_MIN_BUFSIZE] = {0x1B, 0, 0, 0, 0x2, 0};
int rv;

cdrom_unlock(stream);
Expand All @@ -1316,7 +1317,7 @@ int cdrom_open_tray(libretro_vfs_implementation_file *stream)
int cdrom_close_tray(libretro_vfs_implementation_file *stream)
{
/* MMC Command: START STOP UNIT */
unsigned char cdb[] = {0x1B, 0, 0, 0, 0x3, 0};
unsigned char cdb[CDROM_MIN_BUFSIZE] = {0x1B, 0, 0, 0, 0x3, 0};
int rv = cdrom_send_command(stream, DIRECTION_NONE, NULL, 0, cdb, sizeof(cdb), 0);

#ifdef CDROM_DEBUG
Expand Down Expand Up @@ -1495,7 +1496,7 @@ struct string_list* cdrom_get_available_drives(void)
bool cdrom_is_media_inserted(libretro_vfs_implementation_file *stream)
{
/* MMC Command: TEST UNIT READY */
unsigned char cdb[] = {0x00, 0, 0, 0, 0, 0};
unsigned char cdb[CDROM_MIN_BUFSIZE] = {0x00, 0, 0, 0, 0, 0};
int rv = cdrom_send_command(stream, DIRECTION_NONE, NULL, 0, cdb, sizeof(cdb), 0);

#ifdef CDROM_DEBUG
Expand Down
Loading