slackline: fix reallocation memory issue - lchat - A line oriented chat front end for ii.
(HTM) git clone git://git.suckless.org/lchat
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
---
(DIR) commit d671b2273e2283df46dd940dc7ce6a1a3476f9eb
(DIR) parent dbc8751dc6c034967d2b3133a58a627834992e8c
(HTM) Author: Petr Vaněk <arkamar@atlas.cz>
Date: Mon, 26 Sep 2022 16:27:12 +0200
slackline: fix reallocation memory issue
It is necessary to update sl->ptr and sl->last pointers appropriately
after reallocation otherwise backspacing or deleting can work in wrong
memory area.
Diffstat:
M slackline.c | 2 ++
1 file changed, 2 insertions(+), 0 deletions(-)
---
(DIR) diff --git a/slackline.c b/slackline.c
@@ -239,6 +239,8 @@ compose:
if ((nbuf = realloc(sl->buf, sl->bufsize * 2)) == NULL)
return -1;
+ sl->ptr = nbuf + (sl->ptr - sl->buf);
+ sl->last = nbuf + (sl->last - sl->buf);
sl->buf = nbuf;
sl->bufsize *= 2;
}