]> Sergey Matveev's repositories - nnn.git/commitdiff
Fix segfault in readln()
authorsin <sin@2f30.org>
Tue, 21 Oct 2014 14:29:35 +0000 (15:29 +0100)
committersin <sin@2f30.org>
Tue, 21 Oct 2014 14:29:35 +0000 (15:29 +0100)
This could be reproduced simply by doing: [TAB] and backspacing
a few times.

noice.c

diff --git a/noice.c b/noice.c
index ee70d582ebeda790260b0f789fba22eb0e2da531..12c8ae90d5917721de9cfcee793c644485aa540e 100644 (file)
--- a/noice.c
+++ b/noice.c
@@ -287,8 +287,13 @@ readln(void)
                if (c == KEY_BACKSPACE) {
                        getyx(stdscr, y, x);
                        if (x >= x0) {
-                               ln = realloc(ln, (i - 1) * sizeof(*ln));
-                               i--;
+                               if (i > 0) {
+                                       ln = realloc(ln, (i - 1) * sizeof(*ln));
+                                       i--;
+                               } else {
+                                       free(ln);
+                                       ln = NULL;
+                               }
                                move(y, x);
                                printw("%c", ' ');
                                move(y, x);