]> Sergey Matveev's repositories - nnn.git/commitdiff
realloc() behaves like free() if size is 0
authorsin <sin@2f30.org>
Wed, 22 Oct 2014 16:57:59 +0000 (17:57 +0100)
committersin <sin@2f30.org>
Wed, 22 Oct 2014 16:57:59 +0000 (17:57 +0100)
noice.c

diff --git a/noice.c b/noice.c
index e4f86a032aa831d95c8ba31a9499ecf6fbdb3673..638211d83db91c90d73ef6da421ce89d5969b78c 100644 (file)
--- a/noice.c
+++ b/noice.c
@@ -366,9 +366,9 @@ readln(void)
                if (c == KEY_BACKSPACE) {
                        getyx(stdscr, y, x);
                        if (x >= x0) {
+                               i--;
                                if (i > 0) {
-                                       ln = xrealloc(ln, (i - 1) * sizeof(*ln));
-                                       i--;
+                                       ln = xrealloc(ln, i * sizeof(*ln));
                                } else {
                                        free(ln);
                                        ln = NULL;