From 150a513c6c0ae6fc7dfce4c76ec14019f9b34d84 Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Wed, 6 Sep 2017 22:07:25 +1000 Subject: [PATCH] Experiment with line deletion --- utils/magiedit/main.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/utils/magiedit/main.c b/utils/magiedit/main.c index 57765a0..81826fd 100644 --- a/utils/magiedit/main.c +++ b/utils/magiedit/main.c @@ -585,13 +585,21 @@ char *message_editor() { body_lines[i] = body_lines[i+1]; } body_line_count--; - body_lines = (char **)realloc(body_lines, sizeof(char *) * (body_line_count + 1)); + if (body_line_count == 0) { + free(body_lines); + } else { + body_lines = (char **)realloc(body_lines, sizeof(char *) * (body_line_count)); + } } else { if (body_line_count > 0) { memcpy(line, body_lines[body_line_count -1], 81); free(body_lines[body_line_count - 1]); body_line_count--; - body_lines = (char **)realloc(body_lines, sizeof(char *) * (body_line_count + 1)); + if (body_line_count == 0) { + free(body_lines); + } else { + body_lines = (char **)realloc(body_lines, sizeof(char *) * (body_line_count)); + } position_y--; } else { memset(line, 0, 81);