From d53e9a93d24a9e442ffc2d5315a89423ed0a12cf Mon Sep 17 00:00:00 2001 From: mightymax Date: Sun, 7 Jan 2007 21:00:45 +0000 Subject: [PATCH] compiles again under win32 & systems without gzip, added checks for invalid file ptrs --- desmume/src/NDSSystem.c | 3 +++ desmume/src/ROMReader.c | 9 +++++++++ 2 files changed, 12 insertions(+) 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); }