fix crash in fcm convert
This commit is contained in:
parent
d2526bc795
commit
0f873d9812
|
@ -542,11 +542,11 @@ EFCM_CONVERTRESULT convert_fcm(MovieData& md, std::string fname)
|
|||
int movieConvertOffset1=0, movieConvertOffset2=0,movieSyncHackOn=0;
|
||||
|
||||
|
||||
ifstream* fp = (ifstream*)FCEUD_UTF8_fstream(fname, "rb");
|
||||
EMUFILE* fp = FCEUD_UTF8_fstream(fname, "rb");
|
||||
if(!fp) false;
|
||||
|
||||
// read header
|
||||
uint32 magic;
|
||||
uint32 magic = 0;
|
||||
uint32 version;
|
||||
uint8 flags[4];
|
||||
|
||||
|
@ -576,7 +576,7 @@ EFCM_CONVERTRESULT convert_fcm(MovieData& md, std::string fname)
|
|||
}
|
||||
|
||||
|
||||
fp->read((char*)&flags,4);
|
||||
fp->fread((char*)&flags,4);
|
||||
read32le(&framecount, fp);
|
||||
read32le(&rerecord_count, fp);
|
||||
read32le(&moviedatasize, fp);
|
||||
|
@ -584,7 +584,7 @@ EFCM_CONVERTRESULT convert_fcm(MovieData& md, std::string fname)
|
|||
read32le(&firstframeoffset, fp);
|
||||
|
||||
//read header values
|
||||
fp->read((char*)&md.romChecksum,16);
|
||||
fp->fread((char*)&md.romChecksum,16);
|
||||
read32le((uint32*)&md.emuVersion,fp);
|
||||
|
||||
md.romFilename = readNullTerminatedAscii(fp);
|
||||
|
@ -625,9 +625,9 @@ EFCM_CONVERTRESULT convert_fcm(MovieData& md, std::string fname)
|
|||
//analyze input types?
|
||||
//ResetInputTypes();
|
||||
|
||||
fp->seekg(firstframeoffset,ios::beg);
|
||||
fp->fseek(firstframeoffset,SEEK_SET);
|
||||
moviedata = (uint8*)realloc(moviedata, moviedatasize);
|
||||
fp->read((char*)moviedata,moviedatasize);
|
||||
fp->fread((char*)moviedata,moviedatasize);
|
||||
|
||||
frameptr = 0;
|
||||
memset(joop,0,sizeof(joop));
|
||||
|
|
|
@ -553,13 +553,13 @@ std::string stditoa(int n)
|
|||
}
|
||||
|
||||
|
||||
std::string readNullTerminatedAscii(std::istream* is)
|
||||
std::string readNullTerminatedAscii(EMUFILE* is)
|
||||
{
|
||||
std::string ret;
|
||||
ret.reserve(50);
|
||||
for(;;)
|
||||
{
|
||||
int c = is->get();
|
||||
int c = is->fgetc();
|
||||
if(c == 0) break;
|
||||
else ret += (char)c;
|
||||
}
|
||||
|
|
|
@ -63,35 +63,9 @@ char *U16ToHexStr(uint16 a);
|
|||
|
||||
std::string stditoa(int n);
|
||||
|
||||
std::string readNullTerminatedAscii(std::istream* is);
|
||||
std::string readNullTerminatedAscii(EMUFILE* is);
|
||||
|
||||
//extracts a decimal uint from an istream
|
||||
template<typename T> T templateIntegerDecFromIstream(std::istream* is)
|
||||
{
|
||||
unsigned int ret = 0;
|
||||
bool pre = true;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
int c = is->get();
|
||||
if(c == -1) return ret;
|
||||
int d = c - '0';
|
||||
if((d<0 || d>9))
|
||||
{
|
||||
if(!pre)
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
pre = false;
|
||||
ret *= 10;
|
||||
ret += d;
|
||||
}
|
||||
}
|
||||
is->unget();
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<typename T> T templateIntegerDecFromIstream(EMUFILE* is)
|
||||
{
|
||||
unsigned int ret = 0;
|
||||
|
@ -118,33 +92,9 @@ template<typename T> T templateIntegerDecFromIstream(EMUFILE* is)
|
|||
return ret;
|
||||
}
|
||||
|
||||
inline uint32 uint32DecFromIstream(std::istream* is) { return templateIntegerDecFromIstream<uint32>(is); }
|
||||
inline uint64 uint64DecFromIstream(std::istream* is) { return templateIntegerDecFromIstream<uint64>(is); }
|
||||
inline uint32 uint32DecFromIstream(EMUFILE* is) { return templateIntegerDecFromIstream<uint32>(is); }
|
||||
inline uint64 uint64DecFromIstream(EMUFILE* is) { return templateIntegerDecFromIstream<uint64>(is); }
|
||||
|
||||
//puts an optionally 0-padded decimal integer of type T into the ostream (0-padding is quicker)
|
||||
template<typename T, int DIGITS, bool PAD> void putdec(std::ostream* os, T dec)
|
||||
{
|
||||
char temp[DIGITS];
|
||||
int ctr = 0;
|
||||
for(int i=0;i<DIGITS;i++)
|
||||
{
|
||||
int quot = dec/10;
|
||||
int rem = dec%10;
|
||||
temp[DIGITS-1-i] = '0' + rem;
|
||||
if(!PAD)
|
||||
{
|
||||
if(rem != 0) ctr = i;
|
||||
}
|
||||
dec = quot;
|
||||
}
|
||||
if(!PAD)
|
||||
os->write(temp+DIGITS-ctr-1,ctr+1);
|
||||
else
|
||||
os->write(temp,DIGITS);
|
||||
}
|
||||
|
||||
//puts an optionally 0-padded decimal integer of type T into the ostream (0-padding is quicker)
|
||||
template<typename T, int DIGITS, bool PAD> void putdec(EMUFILE* os, T dec)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue