From 6aa99fa078dd0f95f27cb08fb4679bc67bc28558 Mon Sep 17 00:00:00 2001 From: Miciah Dashiel Butler Masters Date: Sun, 27 Jan 2008 18:47:20 +0000 Subject: [PATCH] Add KEYMAP_INVALID value for enum keymap_id and properly check for it get_keymap_id returns -1 when it can't find the keymap. Because the return type of get_keymap_id is enum keymap_id and enum keymap_id did not have any explicit values defined, it could be unsigned, which meant that when get_keymap_id returned -1, it was really returning a huge positive number. This meant that when callers checker whether the return value was negative, they were essentially performing no check at all, so they might give get_keymap_id an invalid keymap name, get back an invalid keymap_id, and use that invalid keymap_id. This commit adds KEYMAP_INVALID = -1 to enum keymap_id and makes all functions that deal with the enumeration use that symbol. --- src/config/kbdbind.c | 6 +++--- src/config/kbdbind.h | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/config/kbdbind.c b/src/config/kbdbind.c index 8899351e..a9018e43 100644 --- a/src/config/kbdbind.c +++ b/src/config/kbdbind.c @@ -551,7 +551,7 @@ bind_key_to_event(unsigned char *ckmap, unsigned char *ckey, int event) action_id_T action_id; enum keymap_id keymap_id = get_keymap_id(ckmap); - if (keymap_id < 0) + if (keymap_id == KEYMAP_INVALID) return gettext("Unrecognised keymap"); if (parse_keystroke(ckey, &kbd) < 0) @@ -870,7 +870,7 @@ bind_do(unsigned char *keymap_str, unsigned char *keystroke_str, struct keybinding *keybinding; keymap_id = get_keymap_id(keymap_str); - if (keymap_id < 0) return 1; + if (keymap_id == KEYMAP_INVALID) return 1; if (parse_keystroke(keystroke_str, &kbd) < 0) return 2; @@ -892,7 +892,7 @@ bind_act(unsigned char *keymap_str, unsigned char *keystroke_str) struct keybinding *keybinding; keymap_id = get_keymap_id(keymap_str); - if (keymap_id < 0) + if (keymap_id == KEYMAP_INVALID) return NULL; keybinding = kbd_stroke_lookup(keymap_id, keystroke_str); diff --git a/src/config/kbdbind.h b/src/config/kbdbind.h index 1a3c7809..8d1e2844 100644 --- a/src/config/kbdbind.h +++ b/src/config/kbdbind.h @@ -13,6 +13,7 @@ struct listbox_item; typedef long action_id_T; enum keymap_id { + KEYMAP_INVALID = -1, KEYMAP_MAIN, KEYMAP_EDIT, KEYMAP_MENU,