commit d671b2273e2283df46dd940dc7ce6a1a3476f9eb
Author:     Petr Vaněk <[email protected]>
AuthorDate: Mon Sep 26 16:27:12 2022 +0200
Commit:     Jan Klemkow <[email protected]>
CommitDate: Sun Oct 2 03:47:29 2022 +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.

diff --git a/slackline.c b/slackline.c
index d93fe7a..bc4dfe9 100644
--- 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;
        }

Reply via email to