fix array-out-of-bounds issue

This commit is contained in:
notaz 2013-08-30 01:35:47 +03:00
parent 4fb435550b
commit cfae1ae179

View file

@ -180,7 +180,7 @@ typedef enum {
CHUNK_CARTHW_ = CHUNK_CARTHW, // 64 (defined in PicoInt) CHUNK_CARTHW_ = CHUNK_CARTHW, // 64 (defined in PicoInt)
} chunk_name_e; } chunk_name_e;
static const char * const chunk_names[] = { static const char * const chunk_names[CHUNK_DEFAULT_COUNT] = {
"INVALID!", "INVALID!",
"M68K state", "M68K state",
"RAM", "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) { \ #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); \ strncpy(sbuff + 9, chunk_names[name], sizeof(sbuff) - 9); \
PicoStateProgressCB(sbuff); \ 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) { \ #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); \ strncpy(sbuff + 9, chunk_names[name], sizeof(sbuff) - 9); \
PicoStateProgressCB(sbuff); \ PicoStateProgressCB(sbuff); \
} \ } \