Fixed a crash related to adding and deleting breakpoints

This commit is contained in:
Lior Halphon 2016-06-10 18:03:12 +03:00
parent ee7e58e44b
commit 6c7dd761e2

View File

@ -448,7 +448,7 @@ static bool breakpoint(GB_gameboy_t *gb, char *arguments)
return true; 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])); memmove(&gb->breakpoints[index + 1], &gb->breakpoints[index], (gb->n_breakpoints - index) * sizeof(gb->breakpoints[0]));
gb->breakpoints[index] = result; gb->breakpoints[index] = result;
gb->n_breakpoints++; gb->n_breakpoints++;
@ -481,9 +481,9 @@ static bool delete(GB_gameboy_t *gb, char *arguments)
return true; 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])); memmove(&gb->breakpoints[index], &gb->breakpoints[index + 1], (gb->n_breakpoints - index) * sizeof(gb->breakpoints[0]));
gb->n_breakpoints--; gb->n_breakpoints--;
gb->breakpoints = realloc(gb->breakpoints, gb->n_breakpoints * sizeof(gb->breakpoints[0]));
gb_log(gb, "Breakpoint removed from %04x\n", result); gb_log(gb, "Breakpoint removed from %04x\n", result);
return true; return true;