]> granicus.if.org Git - nethack/commitdiff
Fix a bug binding menu command to a default object class character
authorPasi Kallinen <paxed@alt.org>
Sun, 25 Sep 2016 15:37:24 +0000 (18:37 +0300)
committerPasi Kallinen <paxed@alt.org>
Sun, 25 Sep 2016 15:38:58 +0000 (18:38 +0300)
Due to a wrong looping variable, it was possible to bind a menu accelerator key
to a default object class.

src/options.c

index 6a0a0d10c5189ae5ab687243de8847c9c5a20293..ebe189e6e5d3e84af751c870a91ff7c3346fd1e4 100644 (file)
@@ -1768,6 +1768,23 @@ char **opp;
     return FALSE;
 }
 
+/* Check if character c is illegal as a menu command key */
+boolean
+illegal_menu_cmd_key(c)
+char c;
+{
+    if (c == 0 || c == '\r' || c == '\n' || c == '\033'
+        || c == ' ' || digit(c) || (letter(c) && c != '@'))
+        return TRUE;
+    else { /* reject default object class symbols */
+        int j;
+        for (j = 1; j < MAXOCLASSES; j++)
+            if (c == def_oc_syms[j].sym)
+                return TRUE;
+    }
+    return FALSE;
+}
+
 void
 parseoptions(opts, tinitial, tfrom_file)
 register char *opts;
@@ -3226,22 +3243,11 @@ boolean tinitial, tfrom_file;
             } else if ((op = string_for_opt(opts, FALSE)) != 0) {
                 int j;
                 char c, op_buf[BUFSZ];
-                boolean isbad = FALSE;
 
                 escapes(op, op_buf);
                 c = *op_buf;
 
-                if (c == 0 || c == '\r' || c == '\n' || c == '\033'
-                    || c == ' ' || digit(c) || (letter(c) && c != '@'))
-                    isbad = TRUE;
-                else /* reject default object class symbols */
-                    for (j = 1; j < MAXOCLASSES; j++)
-                        if (c == def_oc_syms[i].sym) {
-                            isbad = TRUE;
-                            break;
-                        }
-
-                if (isbad)
+                if (illegal_menu_cmd_key(c))
                     badoption(opts);
                 else
                     add_menu_cmd_alias(c, default_menu_cmd_info[i].cmd);