From ae940c79e1c1b50adf8f366402d723ba441dadc5 Mon Sep 17 00:00:00 2001 From: nitsuja Date: Mon, 27 Jul 2009 16:25:00 +0000 Subject: [PATCH] savestate date memory overwrite fix --- desmume/src/saves.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/desmume/src/saves.cpp b/desmume/src/saves.cpp index 7cd66c474..2e06a4e4b 100644 --- a/desmume/src/saves.cpp +++ b/desmume/src/saves.cpp @@ -563,7 +563,8 @@ void scan_savestates() sprintf(filename+strlen(filename), ".ds%d", i); if( stat(filename,&sbuf) == -1 ) continue; savestates[i-1].exists = TRUE; - strncpy(savestates[i-1].date, format_time(sbuf.st_mtime),MAX_PATH); + strncpy(savestates[i-1].date, format_time(sbuf.st_mtime),40); + savestates[i-1].date[40-1] = '\0'; } return ; @@ -593,9 +594,15 @@ void savestate_slot(int num) return; } - savestates[num].exists = TRUE; - if( stat(filename,&sbuf) == -1 ) return; - strncpy(savestates[num].date, format_time(sbuf.st_mtime),MAX_PATH); + if (num >= 0 && num < NB_STATES) + { + if (stat(filename,&sbuf) != -1) + { + savestates[num].exists = TRUE; + strncpy(savestates[num].date, format_time(sbuf.st_mtime),40); + savestates[num].date[40-1] = '\0'; + } + } } void loadstate_slot(int num) @@ -990,7 +997,7 @@ static void loadstate() _MMU_write16(0x04000304, _MMU_read16(0x04000304)); // This should regenerate the graphics configuration - //zero 27-jul-09 : was formerly up to 7F but that wrote to dispfifo which is dumb (one of nitsuja's desynch bugs) + //zero 27-jul-09 : was formerly up to 7F but that wrote to dispfifo which is dumb (one of nitsuja's desynch bugs [that he found, not caused]) for (int i = REG_BASE_DISPA; i<=REG_BASE_DISPA + 0x66; i+=2) _MMU_write16(i, _MMU_read16(i)); for (int i = REG_BASE_DISPB; i<=REG_BASE_DISPB + 0x7F; i+=2)