mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
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.
This commit is contained in:
parent
7e0c0e14e2
commit
6aa99fa078
@ -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);
|
||||
|
@ -13,6 +13,7 @@ struct listbox_item;
|
||||
typedef long action_id_T;
|
||||
|
||||
enum keymap_id {
|
||||
KEYMAP_INVALID = -1,
|
||||
KEYMAP_MAIN,
|
||||
KEYMAP_EDIT,
|
||||
KEYMAP_MENU,
|
||||
|
Loading…
Reference in New Issue
Block a user