From: nethack.rankin Date: Sun, 15 Apr 2012 05:10:22 +0000 (+0000) Subject: more tty extmenu option X-Git-Tag: MOVE2GIT~33 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5fda793c67393946a95f89efbb78bbee5625e4b1;p=nethack more tty extmenu option 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). --- diff --git a/src/cmd.c b/src/cmd.c index f45ff16f9..510315449 100644 --- 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;