From efed1b3deca4749e375c66d84cb367fe7d2e599e Mon Sep 17 00:00:00 2001 From: CaH4e3 Date: Sat, 5 Jan 2013 18:11:31 +0000 Subject: [PATCH] UNIF: little bit verbose/safe chunk loading, fix some crashes --- src/unif.cpp | 61 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 20 deletions(-) diff --git a/src/unif.cpp b/src/unif.cpp index f8aff5ba..fabb32c5 100644 --- a/src/unif.cpp +++ b/src/unif.cpp @@ -122,14 +122,25 @@ static void MooMirroring(void) { } static int DoMirroring(FCEUFILE *fp) { - uint8 t; - t = FCEU_fgetc(fp); - mirrortodo = t; - - { - static char *stuffo[6] = { "Horizontal", "Vertical", "$2000", "$2400", "\"Four-screen\"", "Controlled by Mapper Hardware" }; - if (t < 6) - FCEU_printf(" Name/Attribute Table Mirroring: %s\n", stuffo[t]); + uint8 t, i; + if(uchead.info == 1) { + if ((t = FCEU_fgetc(fp)) == EOF) + return(0); + mirrortodo = t; + { + static char *stuffo[6] = { "Horizontal", "Vertical", "$2000", "$2400", "\"Four-screen\"", "Controlled by Mapper Hardware" }; + if (t < 6) + FCEU_printf(" Name/Attribute Table Mirroring: %s\n", stuffo[t]); + } + } else { + FCEU_printf(" Incorrect Mirroring Chunk Size (%d). Data is:", uchead.info); + for(i = 0; i < uchead.info; i++) { + if ((t = FCEU_fgetc(fp)) == EOF) + return(0); + FCEU_printf(" %02x", t); + } + FCEU_printf("\n Default Name/Attribute Table Mirroring: Horizontal\n", uchead.info); + mirrortodo = 0; } return(1); } @@ -188,19 +199,29 @@ static int DINF(FCEUFILE *fp) { } static int CTRL(FCEUFILE *fp) { - int t; - - if ((t = FCEU_fgetc(fp)) == EOF) - return(0); - /* The information stored in this byte isn't very helpful, but it's - better than nothing...maybe. - */ - - if (t & 1) GameInfo->input[0] = GameInfo->input[1] = SI_GAMEPAD; - else GameInfo->input[0] = GameInfo->input[1] = SI_NONE; - - if (t & 2) GameInfo->input[1] = SI_ZAPPER; + int t, i; + if(uchead.info == 1) { + if ((t = FCEU_fgetc(fp)) == EOF) + return(0); + /* The information stored in this byte isn't very helpful, but it's + better than nothing...maybe. + */ + if (t & 1) + GameInfo->input[0] = GameInfo->input[1] = SI_GAMEPAD; + else + GameInfo->input[0] = GameInfo->input[1] = SI_NONE; + if (t & 2) + GameInfo->input[1] = SI_ZAPPER; + } else { + FCEU_printf(" Incorrect Control Chunk Size (%d). Data is:", uchead.info); + for(i = 0; i < uchead.info; i++) { + t = FCEU_fgetc(fp); + FCEU_printf(" %02x", t); + } + FCEU_printf("\n"); + GameInfo->input[0] = GameInfo->input[1] = SI_GAMEPAD; + } return(1); }