Fix infinite loop when given bad ROMs (one byte files, for example); fix compile error that somehow snuck in.

This commit is contained in:
Alcaro 2013-08-14 10:05:15 +02:00
parent 975e81f9e6
commit 25c0e7c948
2 changed files with 10 additions and 7 deletions

View File

@ -233,7 +233,7 @@ void retro_cheat_set(unsigned index, bool enabled, const char *code)
if (S9xGameGenieToRaw(code, address, val)!=NULL &&
S9xProActionReplayToRaw(code, address, val)!=NULL &&
S9xGoldFingerToRaw(code, address, &sram, val, bytes)!=NULL)
S9xGoldFingerToRaw(code, address, sram, val, bytes)!=NULL)
{ // bad code, ignore
return;
}
@ -252,7 +252,6 @@ void retro_cheat_set(unsigned index, bool enabled, const char *code)
bool retro_load_game(const struct retro_game_info *game)
{
if(game->data == NULL && game->size == 0 && game->path != NULL)
rom_loaded = Memory.LoadROM(game->path);
else

View File

@ -1519,10 +1519,12 @@ bool8 CMemory::LoadROMMem (const uint8 *source, uint32 sourceSize)
strcpy(ROMFilename,"MemoryROM");
int counter=0;
do
{
if (++counter>5) return FALSE;//if we keep failing, just give up after a while or we'll loop forever.
memset(ROM,0, MAX_ROM_SIZE);
memset(&Multi, 0,sizeof(Multi));
memset(&Multi, 0,sizeof(Multi));
memcpy(ROM,source,sourceSize);
}
while(!LoadROMInt(sourceSize));
@ -1537,17 +1539,19 @@ bool8 CMemory::LoadROM (const char *filename)
int32 totalFileSize;
int counter=0;
do
{
if (++counter>5) return FALSE;
memset(ROM,0, MAX_ROM_SIZE);
memset(&Multi, 0,sizeof(Multi));
memset(&Multi, 0,sizeof(Multi));
totalFileSize = FileLoader(ROM, filename, MAX_ROM_SIZE);
if (!totalFileSize)
return (FALSE);
return (FALSE);
if (!Settings.NoPatch)
CheckForAnyPatch(filename, HeaderCount != 0, totalFileSize);
CheckForAnyPatch(filename, HeaderCount != 0, totalFileSize);
}
while(!LoadROMInt(totalFileSize));
@ -3375,7 +3379,7 @@ uint16 CMemory::checksum_calc_sum (uint8 *data, uint32 length)
uint16 CMemory::checksum_mirror_sum (uint8 *start, uint32 &length, uint32 mask)
{
// from NSRT
while (!(length & mask))
while (!(length & mask) && mask)
mask >>= 1;
uint16 part1 = checksum_calc_sum(start, mask);