Fix segfault in readln()

This could be reproduced simply by doing: [TAB] and backspacing
a few times.
This commit is contained in:
sin 2014-10-21 15:29:35 +01:00
parent 330adc995f
commit cfd530b167
1 changed files with 7 additions and 2 deletions

View File

@ -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);