From cfd530b167a36a613fa9e8b55246a7b388c02005 Mon Sep 17 00:00:00 2001
From: sin <sin@2f30.org>
Date: Tue, 21 Oct 2014 15:29:35 +0100
Subject: [PATCH] Fix segfault in readln()

This could be reproduced simply by doing: [TAB] and backspacing
a few times.
---
 noice.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/noice.c b/noice.c
index ee70d582..12c8ae90 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);
-- 
2.51.0