Silence -Walloc-size-larger-than=byte-size

One of the GCC14's optimization heuristic triggered here, suggesting
that the special value of len (size_t) could potentially be lesser than
the file's size (int64_t) but greater than "maximum object size" (set by
byte-size, PTRDIFF_MAX by default).

Use the same type as the file size it's compared to, and adjust the
sentinel value to spell INT64_MAX.
This commit is contained in:
pstef 2025-03-16 16:23:32 +00:00
parent 5c093a7211
commit 3dca8dbf66
1 changed files with 10 additions and 10 deletions

View File

@ -269,7 +269,7 @@ static int intfstream_get_serial(intfstream_t *fd, char *s, size_t len, const ch
} }
static bool intfstream_file_get_serial(const char *name, static bool intfstream_file_get_serial(const char *name,
uint64_t offset, size_t size, char *s, size_t len) uint64_t offset, int64_t size, char *s, size_t len)
{ {
int rv; int rv;
uint8_t *data = NULL; uint8_t *data = NULL;
@ -291,7 +291,7 @@ static bool intfstream_file_get_serial(const char *name,
if (file_size < 0) if (file_size < 0)
goto error; goto error;
if (offset != 0 || size < (size_t) file_size) if (offset != 0 || size < file_size)
{ {
if (intfstream_seek(fd, (int64_t)offset, SEEK_SET) == -1) if (intfstream_seek(fd, (int64_t)offset, SEEK_SET) == -1)
goto error; goto error;
@ -364,7 +364,7 @@ static int task_database_gdi_get_serial(const char *name, char *s, size_t len)
return 0; return 0;
} }
return intfstream_file_get_serial(track_path, 0, SIZE_MAX, s, len); return intfstream_file_get_serial(track_path, 0, INT64_MAX, s, len);
} }
static int task_database_chd_get_serial(const char *name, char *serial, size_t len) static int task_database_chd_get_serial(const char *name, char *serial, size_t len)
@ -385,7 +385,7 @@ static int task_database_chd_get_serial(const char *name, char *serial, size_t l
} }
static bool intfstream_file_get_crc(const char *name, static bool intfstream_file_get_crc(const char *name,
uint64_t offset, size_t len, uint32_t *crc) uint64_t offset, int64_t len, uint32_t *crc)
{ {
bool rv; bool rv;
intfstream_t *fd = intfstream_open_file(name, intfstream_t *fd = intfstream_open_file(name,
@ -407,7 +407,7 @@ static bool intfstream_file_get_crc(const char *name,
if (file_size < 0) if (file_size < 0)
goto error; goto error;
if (offset != 0 || len < (uint64_t) file_size) if (offset != 0 || len < file_size)
{ {
if (intfstream_seek(fd, (int64_t)offset, SEEK_SET) == -1) if (intfstream_seek(fd, (int64_t)offset, SEEK_SET) == -1)
goto error; goto error;
@ -480,7 +480,7 @@ static int task_database_gdi_get_crc(const char *name, uint32_t *crc)
return 0; return 0;
} }
return intfstream_file_get_crc(track_path, 0, SIZE_MAX, crc); return intfstream_file_get_crc(track_path, 0, INT64_MAX, crc);
} }
static bool task_database_chd_get_crc(const char *name, uint32_t *crc) static bool task_database_chd_get_crc(const char *name, uint32_t *crc)
@ -624,7 +624,7 @@ static int task_database_iterate_playlist(
db->type = DATABASE_TYPE_CRC_LOOKUP; db->type = DATABASE_TYPE_CRC_LOOKUP;
/* first check crc of archive itself */ /* first check crc of archive itself */
return intfstream_file_get_crc(name, return intfstream_file_get_crc(name,
0, SIZE_MAX, &db_state->archive_crc); 0, INT64_MAX, &db_state->archive_crc);
#else #else
break; break;
#endif #endif
@ -656,7 +656,7 @@ static int task_database_iterate_playlist(
case FILE_TYPE_WIA: case FILE_TYPE_WIA:
case FILE_TYPE_ISO: case FILE_TYPE_ISO:
db_state->serial[0] = '\0'; db_state->serial[0] = '\0';
intfstream_file_get_serial(name, 0, SIZE_MAX, db_state->serial, sizeof(db_state->serial)); intfstream_file_get_serial(name, 0, INT64_MAX, db_state->serial, sizeof(db_state->serial));
db->type = DATABASE_TYPE_SERIAL_LOOKUP; db->type = DATABASE_TYPE_SERIAL_LOOKUP;
break; break;
case FILE_TYPE_CHD: case FILE_TYPE_CHD:
@ -675,7 +675,7 @@ static int task_database_iterate_playlist(
default: default:
db_state->serial[0] = '\0'; db_state->serial[0] = '\0';
db->type = DATABASE_TYPE_CRC_LOOKUP; db->type = DATABASE_TYPE_CRC_LOOKUP;
return intfstream_file_get_crc(name, 0, SIZE_MAX, &db_state->crc); return intfstream_file_get_crc(name, 0, INT64_MAX, &db_state->crc);
} }
return 1; return 1;
@ -1136,7 +1136,7 @@ static int task_database_iterate_serial_lookup(
if (task_database_check_serial_and_crc(db_state)) if (task_database_check_serial_and_crc(db_state))
{ {
if (db_state->crc == 0) if (db_state->crc == 0)
intfstream_file_get_crc(name, 0, SIZE_MAX, &db_state->crc); intfstream_file_get_crc(name, 0, INT64_MAX, &db_state->crc);
if (db_state->crc == db_info_entry->crc32) if (db_state->crc == db_info_entry->crc32)
return database_info_list_iterate_found_match(_db, return database_info_list_iterate_found_match(_db,
db_state, db, NULL); db_state, db, NULL);