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.)
This commit is contained in:
Benno Schulenberg 2016-06-14 14:39:56 +02:00
parent 883373cd76
commit 7165bd5c33
1 changed files with 2 additions and 2 deletions

View File

@ -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;