add_keybinding: always allocate the new keybinding
authorJonas Fonseca <fonseca@diku.dk>
Thu, 28 Sep 2006 11:51:38 +0000 (13:51 +0200)
committerJonas Fonseca <fonseca@antimatter.localdomain>
Thu, 28 Sep 2006 11:51:38 +0000 (13:51 +0200)
Fixes infinite loop repoted by Miciah. Also simply continue when wgetch
returns ERR (-1) instead of calling get_keybinding() etc.

tig.c

diff --git a/tig.c b/tig.c
index aac7c4e..6c2b7d0 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -767,10 +767,9 @@ static struct keybinding *keybindings[ARRAY_SIZE(keymap_table)];
 static void
 add_keybinding(enum keymap keymap, enum request request, int key)
 {
-       struct keybinding *keybinding = keybindings[keymap];
+       struct keybinding *keybinding;
 
-       if (!keybinding)
-               keybinding = calloc(1, sizeof(*keybinding));
+       keybinding = calloc(1, sizeof(*keybinding));
        if (!keybinding)
                die("Failed to allocate keybinding");
 
@@ -3532,6 +3531,8 @@ main(int argc, char *argv[])
 
                /* Refresh, accept single keystroke of input */
                key = wgetch(status_win);
+               if (key == ERR)
+                       continue;
 
                request = get_keybinding(display[current_view]->keymap, key);