From cfae1ae17956a94d7deae336ce6b9571b3f825f1 Mon Sep 17 00:00:00 2001 From: notaz Date: Fri, 30 Aug 2013 01:35:47 +0300 Subject: [PATCH] fix array-out-of-bounds issue --- pico/state.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pico/state.c b/pico/state.c index a3695970..f9a7f839 100644 --- a/pico/state.c +++ b/pico/state.c @@ -180,7 +180,7 @@ typedef enum { CHUNK_CARTHW_ = CHUNK_CARTHW, // 64 (defined in PicoInt) } chunk_name_e; -static const char * const chunk_names[] = { +static const char * const chunk_names[CHUNK_DEFAULT_COUNT] = { "INVALID!", "M68K state", "RAM", @@ -237,7 +237,7 @@ static int write_chunk(chunk_name_e name, int len, void *data, void *file) } #define CHECKED_WRITE(name,len,data) { \ - if (PicoStateProgressCB && name < CHUNK_DEFAULT_COUNT) { \ + if (PicoStateProgressCB && name < CHUNK_DEFAULT_COUNT && chunk_names[name]) { \ strncpy(sbuff + 9, chunk_names[name], sizeof(sbuff) - 9); \ PicoStateProgressCB(sbuff); \ } \ @@ -245,7 +245,7 @@ static int write_chunk(chunk_name_e name, int len, void *data, void *file) } #define CHECKED_WRITE_BUFF(name,buff) { \ - if (PicoStateProgressCB && name < CHUNK_DEFAULT_COUNT) { \ + if (PicoStateProgressCB && name < CHUNK_DEFAULT_COUNT && chunk_names[name]) { \ strncpy(sbuff + 9, chunk_names[name], sizeof(sbuff) - 9); \ PicoStateProgressCB(sbuff); \ } \ -- 2.39.5