aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar sin <sin@2f30.org>2014-10-21 15:29:35 +0100
committerGravatar sin <sin@2f30.org>2014-10-21 15:29:35 +0100
commitcfd530b167a36a613fa9e8b55246a7b388c02005 (patch)
treebf272f17c8932e75f6abe10ff85e2f0bf5b4dd35
parent330adc995f4528a29626b34da0a3d885b98139f7 (diff)
downloadnnn-cfd530b167a36a613fa9e8b55246a7b388c02005.tar.gz
Fix segfault in readln()
This could be reproduced simply by doing: [TAB] and backspacing a few times.
-rw-r--r--noice.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/noice.c b/noice.c
index ee70d58..12c8ae9 100644
--- 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);