]> granicus.if.org Git - nethack/commitdiff
more tty extmenu option
authornethack.rankin <nethack.rankin>
Sun, 15 Apr 2012 05:10:22 +0000 (05:10 +0000)
committernethack.rankin <nethack.rankin>
Sun, 15 Apr 2012 05:10:22 +0000 (05:10 +0000)
     Change extcmd_via_menu() so that the code which guards against overflow
when gathering menu entries is always present.  Now only the explanatory
message when overflow is discovered remains conditional upon DEBUG || BETA.
And make MAX_EXT_CMD actually be the maximum number of extended commands
supported by the menu, instead of MAX_EXT_CMD-2 (which was an off-by-one
bug; capacity for MAX_EXT_CMD-1 was available, but the last slot was always
left unused except if/when unchecked overflow occured).

src/cmd.c

index f45ff16f9667ff5a44ca24c694a52595fa8ae545..51031544996fca33cd8533335958615b185d4bee 100644 (file)
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -357,7 +357,9 @@ doextlist(VOID_ARGS)        /* here after #? - now list all full-word commands */
 #define MAX_EXT_CMD 50         /* Change if we ever have > 50 ext cmds */
 /*
  * This is currently used only by the tty port and is
- * controlled via runtime option 'extmenu'
+ * controlled via runtime option 'extmenu'.
+ * ``# ?'' is counted towards the limit of the number of commands,
+ * so we actually support MAX_EXT_CMD-1 "real" extended commands.
  */
 int
 extcmd_via_menu() /* here after # - now show pick-list of possible commands */
@@ -366,7 +368,7 @@ extcmd_via_menu() /* here after # - now show pick-list of possible commands */
     menu_item *pick_list = (menu_item *)0;
     winid win;
     anything any;
-    const struct ext_func_tab *choices[MAX_EXT_CMD];
+    const struct ext_func_tab *choices[MAX_EXT_CMD + 1];
     char buf[BUFSZ];
     char cbuf[QBUFSZ], prompt[QBUFSZ], fmtstr[20];
     int i, n, nchoices, acount;
@@ -384,20 +386,20 @@ extcmd_via_menu() /* here after # - now show pick-list of possible commands */
        /* populate choices */
        for (efp = extcmdlist; efp->ef_txt; efp++) {
            if (!matchlevel || !strncmp(efp->ef_txt, cbuf, matchlevel)) {
-               choices[i++] = efp;
+               choices[i] = efp;
                if ((int)strlen(efp->ef_desc) > biggest) {
                    biggest = strlen(efp->ef_desc);
                    Sprintf(fmtstr, "%%-%ds", biggest + 15);
                }
+               if (++i > MAX_EXT_CMD) {
 # if defined(DEBUG) || defined(BETA)
-               if (i >= MAX_EXT_CMD - 2) {
                    impossible(
        "Exceeded %d extended commands in doextcmd() menu; 'extmenu' disabled.",
-                              MAX_EXT_CMD - 2);
+                              MAX_EXT_CMD);
+# endif        /* DEBUG || BETA */
                    iflags.extmenu = 0;
                    return -1;
                }
-# endif        /* DEBUG || BETA */
            }
        }
        choices[i] = (struct ext_func_tab *)0;