commit cfd530b167a36a613fa9e8b55246a7b388c02005
parent 330adc995f4528a29626b34da0a3d885b98139f7
Author: sin <sin@2f30.org>
Date: Tue, 21 Oct 2014 15:29:35 +0100
Fix segfault in readln()
This could be reproduced simply by doing: [TAB] and backspacing
a few times.
Diffstat:
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git 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);