From 6c7dd761e2c6ffb65942502abf0f4f0b8036f174 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 10 Jun 2016 18:03:12 +0300 Subject: [PATCH] Fixed a crash related to adding and deleting breakpoints --- Core/debugger.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/debugger.c b/Core/debugger.c index 33053b98..62615189 100644 --- a/Core/debugger.c +++ b/Core/debugger.c @@ -448,7 +448,7 @@ static bool breakpoint(GB_gameboy_t *gb, char *arguments) return true; } - gb->breakpoints = realloc(gb->breakpoints, gb->n_breakpoints * sizeof(gb->breakpoints[0])); + gb->breakpoints = realloc(gb->breakpoints, (gb->n_breakpoints + 1) * sizeof(gb->breakpoints[0])); memmove(&gb->breakpoints[index + 1], &gb->breakpoints[index], (gb->n_breakpoints - index) * sizeof(gb->breakpoints[0])); gb->breakpoints[index] = result; gb->n_breakpoints++; @@ -481,9 +481,9 @@ static bool delete(GB_gameboy_t *gb, char *arguments) return true; } - gb->breakpoints = realloc(gb->breakpoints, gb->n_breakpoints * sizeof(gb->breakpoints[0])); memmove(&gb->breakpoints[index], &gb->breakpoints[index + 1], (gb->n_breakpoints - index) * sizeof(gb->breakpoints[0])); gb->n_breakpoints--; + gb->breakpoints = realloc(gb->breakpoints, gb->n_breakpoints * sizeof(gb->breakpoints[0])); gb_log(gb, "Breakpoint removed from %04x\n", result); return true;