diff --git a/desmume/src/NDSSystem.c b/desmume/src/NDSSystem.c index 4ecfe8a8b..5ec43dc05 100644 --- a/desmume/src/NDSSystem.c +++ b/desmume/src/NDSSystem.c @@ -197,6 +197,7 @@ int NDS_LoadROM(const char *filename, int bmtype, u32 bmsize) type = ROM_DSGBA; file = reader->Init(filename); + if (!file) return -1 ; size = reader->Size(file); if(type == ROM_DSGBA) @@ -273,6 +274,8 @@ void NDS_Reset(void) u32 dst; NDS_header * header = NDS_getROMHeader(); + if (!header) return ; + execute = FALSE; MMU_clearMem(); diff --git a/desmume/src/ROMReader.c b/desmume/src/ROMReader.c index 74756d17f..15ff3744e 100644 --- a/desmume/src/ROMReader.c +++ b/desmume/src/ROMReader.c @@ -4,6 +4,7 @@ ROMReader_struct * ROMReaderInit(const char ** filename) { +#ifdef HAVE_LIBZ if(!strcasecmp(".gz", *filename + (strlen(*filename) - 3))) { *filename -= 3; @@ -13,6 +14,9 @@ ROMReader_struct * ROMReaderInit(const char ** filename) { return &STDROMReader; } +#else + return &STDROMReader; +#endif } void * STDROMReaderInit(const char * filename); @@ -39,6 +43,7 @@ void * STDROMReaderInit(const char * filename) void STDROMReaderDeInit(void * file) { + if (!file) return ; fclose(file); } @@ -46,6 +51,8 @@ u32 STDROMReaderSize(void * file) { u32 size; + if (!file) return 0 ; + fseek(file, 0, SEEK_END); size = ftell(file); fseek(file, 0, SEEK_SET); @@ -55,11 +62,13 @@ u32 STDROMReaderSize(void * file) int STDROMReaderSeek(void * file, int offset, int whence) { + if (!file) return 0 ; return fseek(file, offset, whence); } int STDROMReaderRead(void * file, void * buffer, u32 size) { + if (!file) return 0 ; return fread(buffer, 1, size, file); }