From 7165bd5c33a04d8b61bdaa2c63214547cd2c08d4 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Tue, 14 Jun 2016 14:39:56 +0200 Subject: [PATCH] input: don't allocate too much, and don't move too many To add a character, one does not need to allocate twice its size. And the amount to be moved does not depend on the size of the new character; it just needs to include the terminating zero. (This fixes in do_output() the same logical mistakes that were fixed in do_statusbar_output() last February, in acf19bd and 7c0e433.) --- src/nano.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nano.c b/src/nano.c index 27e1c7da..f84fb441 100644 --- a/src/nano.c +++ b/src/nano.c @@ -1892,13 +1892,13 @@ void do_output(char *output, size_t output_len, bool allow_cntrls) /* More dangerousness fun =) */ openfile->current->data = charealloc(openfile->current->data, - current_len + (char_buf_len * 2)); + current_len + char_buf_len + 1); assert(openfile->current_x <= current_len); charmove(openfile->current->data + openfile->current_x + char_buf_len, openfile->current->data + openfile->current_x, - current_len - openfile->current_x + char_buf_len); + current_len - openfile->current_x + 1); strncpy(openfile->current->data + openfile->current_x, char_buf, char_buf_len); current_len += char_buf_len;