Skip to content

Commit a6c82df

Browse files
committed
(task_database) Use size_t for size to prevent narrowing issue
1 parent ecc5c18 commit a6c82df

3 files changed

Lines changed: 16 additions & 16 deletions

File tree

tasks/task_database.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ static int intfstream_get_serial(intfstream_t *fd, char *serial, size_t serial_l
251251
}
252252

253253
static bool intfstream_file_get_serial(const char *name,
254-
uint64_t offset, uint64_t size, char *serial, size_t serial_len)
254+
uint64_t offset, size_t size, char *serial, size_t serial_len)
255255
{
256256
int rv;
257257
uint8_t *data = NULL;
@@ -273,12 +273,12 @@ static bool intfstream_file_get_serial(const char *name,
273273
if (file_size < 0)
274274
goto error;
275275

276-
if (offset != 0 || size < (uint64_t) file_size)
276+
if (offset != 0 || size < (size_t) file_size)
277277
{
278278
if (intfstream_seek(fd, (int64_t)offset, SEEK_SET) == -1)
279279
goto error;
280280

281-
data = (uint8_t*)malloc((size_t)size);
281+
data = (uint8_t*)malloc(size);
282282

283283
if (intfstream_read(fd, data, size) != (int64_t) size)
284284
{
@@ -312,10 +312,10 @@ static bool intfstream_file_get_serial(const char *name,
312312
static int task_database_cue_get_serial(const char *name, char* serial, size_t serial_len)
313313
{
314314
char track_path[PATH_MAX_LENGTH];
315-
uint64_t offset = 0;
316-
uint64_t size = 0;
315+
uint64_t offset = 0;
316+
size_t size = 0;
317317

318-
track_path[0] = '\0';
318+
track_path[0] = '\0';
319319

320320
if (cue_find_track(name, true, &offset, &size, track_path,
321321
sizeof(track_path)) < 0)
@@ -429,7 +429,7 @@ static int task_database_cue_get_crc(const char *name, uint32_t *crc)
429429
{
430430
char track_path[PATH_MAX_LENGTH];
431431
uint64_t offset = 0;
432-
uint64_t size = 0;
432+
size_t size = 0;
433433

434434
track_path[0] = '\0';
435435

@@ -443,7 +443,7 @@ static int task_database_cue_get_crc(const char *name, uint32_t *crc)
443443
return 0;
444444
}
445445

446-
return intfstream_file_get_crc(track_path, offset, (size_t)size, crc);
446+
return intfstream_file_get_crc(track_path, offset, size, crc);
447447
}
448448

449449
static int task_database_gdi_get_crc(const char *name, uint32_t *crc)

tasks/task_database_cue.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ int detect_scd_game(intfstream_t *fd, char *s, size_t len, const char *filename)
638638
check_suffix_50[2] = '\0';
639639

640640
/** redump serials are built differently for each prefix **/
641-
if ( pre_game_id[0] == 'T'
641+
if ( pre_game_id[0] == 'T'
642642
&& pre_game_id[1] == '-')
643643
{
644644
if (region_id == 'U' || region_id == 'J')
@@ -662,7 +662,7 @@ int detect_scd_game(intfstream_t *fd, char *s, size_t len, const char *filename)
662662
cue_append_multi_disc_suffix(s, filename);
663663
return true;
664664
}
665-
else if (pre_game_id[0] == 'G'
665+
else if (pre_game_id[0] == 'G'
666666
&& pre_game_id[1] == '-')
667667
{
668668
if ((index = string_index_last_occurance(pre_game_id, '-')) == -1)
@@ -823,7 +823,7 @@ int detect_dc_game(intfstream_t *fd, char *s, size_t len, const char *filename)
823823
raw_game_id[10] = '\0';
824824

825825
/** Scrub files with bad data and log **/
826-
if ( raw_game_id[0] == '\0'
826+
if ( raw_game_id[0] == '\0'
827827
|| raw_game_id[0] == ' ')
828828
{
829829
#ifdef DEBUG
@@ -1016,7 +1016,7 @@ int detect_wii_game(intfstream_t *fd, char *s, size_t len, const char *filename)
10161016
raw_game_id[6] = '\0';
10171017

10181018
/** Scrub files with bad data and log **/
1019-
if ( raw_game_id[0] == '\0'
1019+
if ( raw_game_id[0] == '\0'
10201020
|| raw_game_id[0] == ' ')
10211021
{
10221022
#ifdef DEBUG
@@ -1132,7 +1132,7 @@ static int64_t intfstream_get_file_size(const char *path)
11321132

11331133
static bool update_cand(int64_t *cand_index, int64_t *last_index,
11341134
uint64_t *largest, char *last_file, uint64_t *offset,
1135-
uint64_t *size, char *track_path, uint64_t max_len)
1135+
size_t *size, char *track_path, uint64_t max_len)
11361136
{
11371137
if (*cand_index != -1)
11381138
{
@@ -1141,7 +1141,7 @@ static bool update_cand(int64_t *cand_index, int64_t *last_index,
11411141
*largest = *last_index - *cand_index;
11421142
strlcpy(track_path, last_file, (size_t)max_len);
11431143
*offset = *cand_index;
1144-
*size = *largest;
1144+
*size = (size_t)*largest;
11451145
*cand_index = -1;
11461146
return true;
11471147
}
@@ -1151,7 +1151,7 @@ static bool update_cand(int64_t *cand_index, int64_t *last_index,
11511151
}
11521152

11531153
int cue_find_track(const char *cue_path, bool first,
1154-
uint64_t *offset, uint64_t *size, char *track_path, uint64_t max_len)
1154+
uint64_t *offset, size_t *size, char *track_path, uint64_t max_len)
11551155
{
11561156
int rv;
11571157
intfstream_info_t info;

tasks/task_database_cue.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ int detect_wii_game(intfstream_t *fd, char *s, size_t len,
4545
int detect_system(intfstream_t *fd, const char **system_name,
4646
const char * filename);
4747
int cue_find_track(const char *cue_path, bool first, uint64_t *offset,
48-
uint64_t *size, char *track_path, uint64_t max_len);
48+
size_t *size, char *track_path, uint64_t max_len);
4949
bool cue_next_file(intfstream_t *fd, const char *cue_path,
5050
char *s, uint64_t len);
5151
int gdi_find_track(const char *gdi_path, bool first, char *track_path,

0 commit comments

Comments
 (0)