nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 7165bd5c33a04d8b61bdaa2c63214547cd2c08d4
parent 883373cd76044a5662a50c3d1c6b7dd3145f9f7d
Author: Benno Schulenberg <bensberg@justemail.net>
Date:   Tue, 14 Jun 2016 14:39:56 +0200

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.)

Diffstat:
Msrc/nano.c | 4++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git 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;