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.)
master
parent
883373cd76
commit
7165bd5c33
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue