mirror of
https://github.com/holub/mame
synced 2025-07-07 02:50:50 +03:00
The right fix is to not compare against array index -1.
This commit is contained in:
parent
e82fa6e24e
commit
d73542e199
@ -141,7 +141,7 @@ cdrom_file *cdrom_open(const char *inputfile)
|
||||
file_error filerr = core_fopen(file->track_info.track[i].fname, OPEN_FLAG_READ, &file->fhandle[i]);
|
||||
if (filerr != FILERR_NONE)
|
||||
{
|
||||
fprintf(stderr, "Unable to open file: %s\n", file->track_info.track[i].fname);
|
||||
fprintf(stderr, "Unable to open file: %s\n", file->track_info.track[i].fname.cstr());
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ static int msf_to_frames( char *token )
|
||||
length in bytes of the data and the offset in
|
||||
bytes to where the data starts in the file.
|
||||
-------------------------------------------------*/
|
||||
static UINT32 parse_wav_sample(char *filename, UINT32 *dataoffs)
|
||||
static UINT32 parse_wav_sample(const char *filename, UINT32 *dataoffs)
|
||||
{
|
||||
unsigned long offset = 0;
|
||||
UINT32 length, rate, filesize;
|
||||
@ -387,10 +387,8 @@ chd_error chdcd_parse_nero(const char *tocfname, cdrom_toc &outtoc, chdcd_track_
|
||||
index1 = read_uint64(infile);
|
||||
index2 = read_uint64(infile);
|
||||
|
||||
//printf("Track %d: sector size %d mode %x index0 %llx index1 %llx index2 %llx (pregap %d sectors, length %d sectors)\n", track, size, mode, index0, index1, index2, (UINT32)(index1-index0)/size, (UINT32)(index2-index1)/size);
|
||||
// outinfo.track[track-1].fname.cpy(path.cstr()).cat(tocfname);
|
||||
strncpy(outinfo.track[track-1].fname, path.cstr(), 256);
|
||||
strncat(outinfo.track[track-1].fname, tocfname, 256);
|
||||
// printf("Track %d: sector size %d mode %x index0 %llx index1 %llx index2 %llx (pregap %d sectors, length %d sectors)\n", track, size, mode, index0, index1, index2, (UINT32)(index1-index0)/size, (UINT32)(index2-index1)/size);
|
||||
outinfo.track[track-1].fname.cpy(path).cat(tocfname);
|
||||
outinfo.track[track-1].offset = offset + (UINT32)(index1-index0);
|
||||
outinfo.track[track-1].idx0offs = 0;
|
||||
outinfo.track[track-1].idx1offs = 0;
|
||||
@ -540,8 +538,7 @@ static chd_error chdcd_parse_gdi(const char *tocfname, cdrom_toc &outtoc, chdcd_
|
||||
} while(tok!=NULL && (strrchr(tok,'"')-tok !=(strlen(tok)-1)));
|
||||
name = name.delchr('"');
|
||||
}
|
||||
strncpy(outinfo.track[trknum].fname, path.cstr(), 256);
|
||||
strncat(outinfo.track[trknum].fname, name, 256);
|
||||
outinfo.track[trknum].fname.cpy(path).cat(name);
|
||||
|
||||
sz=get_file_size(outinfo.track[trknum].fname);
|
||||
|
||||
@ -590,7 +587,7 @@ chd_error chdcd_parse_cue(const char *tocfname, cdrom_toc &outtoc, chdcd_track_i
|
||||
FILE *infile;
|
||||
int i, trknum;
|
||||
static char token[512];
|
||||
static char lastfname[256];
|
||||
astring lastfname;
|
||||
UINT32 wavlen, wavoffs;
|
||||
astring path = astring(tocfname);
|
||||
|
||||
@ -626,8 +623,7 @@ chd_error chdcd_parse_cue(const char *tocfname, cdrom_toc &outtoc, chdcd_track_i
|
||||
TOKENIZE
|
||||
|
||||
/* keep the filename */
|
||||
strncpy(lastfname, path.cstr(), 256);
|
||||
strncat(lastfname, token, 256);
|
||||
lastfname.cpy(path).cat(token);
|
||||
|
||||
/* get the file type */
|
||||
TOKENIZE
|
||||
@ -652,7 +648,7 @@ chd_error chdcd_parse_cue(const char *tocfname, cdrom_toc &outtoc, chdcd_track_i
|
||||
if (err != FILERR_NONE) printf("holy moley!\n");
|
||||
else core_fclose(fhand);
|
||||
|
||||
printf("ERROR: couldn't read [%s] or not a valid .WAV\n", lastfname);
|
||||
printf("ERROR: couldn't read [%s] or not a valid .WAV\n", lastfname.cstr());
|
||||
return CHDERR_FILE_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
@ -690,7 +686,7 @@ chd_error chdcd_parse_cue(const char *tocfname, cdrom_toc &outtoc, chdcd_track_i
|
||||
outinfo.track[trknum].idx0offs = -1;
|
||||
outinfo.track[trknum].idx1offs = 0;
|
||||
|
||||
strncpy(outinfo.track[trknum].fname, lastfname, 256); // default filename to the last one
|
||||
outinfo.track[trknum].fname.cpy(lastfname); // default filename to the last one
|
||||
|
||||
// printf("trk %d: fname %s offset %d\n", trknum, outinfo.track[trknum].fname.cstr(), outinfo.track[trknum].offset);
|
||||
|
||||
@ -778,12 +774,12 @@ chd_error chdcd_parse_cue(const char *tocfname, cdrom_toc &outtoc, chdcd_track_i
|
||||
if (trknum == (outtoc.numtrks-1))
|
||||
{
|
||||
/* if we have the same filename as the last track, do it that way */
|
||||
if (outinfo.track[trknum].fname == outinfo.track[trknum-1].fname)
|
||||
if (trknum != 0 && outinfo.track[trknum].fname == outinfo.track[trknum-1].fname)
|
||||
{
|
||||
tlen = get_file_size(outinfo.track[trknum].fname);
|
||||
tlen = get_file_size(outinfo.track[trknum].fname.cstr());
|
||||
if (tlen == 0)
|
||||
{
|
||||
printf("ERROR: couldn't find bin file [%s]\n", outinfo.track[trknum-1].fname);
|
||||
printf("ERROR: couldn't find bin file [%s]\n", outinfo.track[trknum-1].fname.cstr());
|
||||
return CHDERR_FILE_NOT_FOUND;
|
||||
}
|
||||
outinfo.track[trknum].offset = outinfo.track[trknum-1].offset + outtoc.tracks[trknum-1].frames * (outtoc.tracks[trknum-1].datasize + outtoc.tracks[trknum-1].subsize);
|
||||
@ -794,7 +790,7 @@ chd_error chdcd_parse_cue(const char *tocfname, cdrom_toc &outtoc, chdcd_track_i
|
||||
tlen = get_file_size(outinfo.track[trknum].fname);
|
||||
if (tlen == 0)
|
||||
{
|
||||
printf("ERROR: couldn't find bin file [%s]\n", outinfo.track[trknum-1].fname);
|
||||
printf("ERROR: couldn't find bin file [%s]\n", outinfo.track[trknum-1].fname.cstr());
|
||||
return CHDERR_FILE_NOT_FOUND;
|
||||
}
|
||||
tlen /= (outtoc.tracks[trknum].datasize + outtoc.tracks[trknum].subsize);
|
||||
@ -829,7 +825,7 @@ chd_error chdcd_parse_cue(const char *tocfname, cdrom_toc &outtoc, chdcd_track_i
|
||||
tlen = get_file_size(outinfo.track[trknum].fname);
|
||||
if (tlen == 0)
|
||||
{
|
||||
printf("ERROR: couldn't find bin file [%s]\n", outinfo.track[trknum].fname);
|
||||
printf("ERROR: couldn't find bin file [%s]\n", outinfo.track[trknum].fname.cstr());
|
||||
return CHDERR_FILE_NOT_FOUND;
|
||||
}
|
||||
tlen /= (outtoc.tracks[trknum].datasize + outtoc.tracks[trknum].subsize);
|
||||
@ -912,8 +908,7 @@ chd_error chdcd_parse_toc(const char *tocfname, cdrom_toc &outtoc, chdcd_track_i
|
||||
TOKENIZE
|
||||
|
||||
/* keep the filename */
|
||||
strncpy(outinfo.track[trknum].fname, path.cstr(), 256);
|
||||
strncat(outinfo.track[trknum].fname, token, 256);
|
||||
outinfo.track[trknum].fname.cpy(path).cat(token);
|
||||
|
||||
/* get either the offset or the length */
|
||||
TOKENIZE
|
||||
|
@ -17,9 +17,9 @@
|
||||
struct chdcd_track_input_entry
|
||||
{
|
||||
chdcd_track_input_entry() { reset(); }
|
||||
void reset() { fname[0] = '\0'; offset = idx0offs = idx1offs = 0; swap = false; }
|
||||
void reset() { fname.reset(); offset = idx0offs = idx1offs = 0; swap = false; }
|
||||
|
||||
char fname[1024]; // filename for each track
|
||||
astring fname; // filename for each track
|
||||
UINT32 offset; // offset in the data file for each track
|
||||
bool swap; // data needs to be byte swapped
|
||||
UINT32 idx0offs;
|
||||
|
Loading…
Reference in New Issue
Block a user