Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix :emenu crash when it's associated with a macaction in a non-valid mode #1305

Merged
merged 1 commit into from
Oct 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions src/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -2376,9 +2376,24 @@ execute_menu(exarg_T *eap, vimmenu_T *menu, int mode_idx)
if (idx == MENU_INDEX_INVALID || eap == NULL)
idx = MENU_INDEX_NORMAL;

if (menu->strings[idx] != NULL && menu->strings[idx][0] != NUL
&& (menu->modes & (1 << idx)))
if (menu->strings[idx] != NULL && (menu->modes & (1 << idx)))
{
#ifdef FEAT_GUI_MACVIM
// When a menu is bound to <Nop>, we let :emenu fall through to execute
// the associated macaction (if one exists) instead. Otherwise, we
// simply execute the associated Vim command. Note that if you
// physically press the menu item (or the associated shortcut key), the
// macaction is always invoked even if the menu isn't bound to <Nop>.
if (menu->mac_action != NULL && menu->strings[idx] != NULL && menu->strings[idx][0] == NUL)
{
// Count on the fact taht ex_macaction() only looks at eap->arg.
old_arg = eap->arg;
eap->arg = menu->mac_action;
ex_macaction(eap);
eap->arg = old_arg;
}
#endif // FEAT_GUI_MACVIM

// When executing a script or function execute the commands right now.
// Also for the window toolbar.
// Otherwise put them in the typeahead buffer.
Expand Down Expand Up @@ -2425,20 +2440,6 @@ execute_menu(exarg_T *eap, vimmenu_T *menu, int mode_idx)
default:
mode = (char_u *)"Normal";
}
#ifdef FEAT_GUI_MACVIM
if (menu->mac_action != NULL && menu->strings[idx][0] == NUL)
{
// This allows us to bind a menu to an action without mapping to
// anything so that pressing the menu's key equivalent and typing
// ":emenu ..." does the same thing. (HACK: We count on the fact
// that ex_macaction() only looks at eap->arg.)
old_arg = eap->arg;
eap->arg = menu->mac_action;
ex_macaction(eap);
eap->arg = old_arg;
}
else
#endif // FEAT_GUI_MACVIM
semsg(_(e_menu_not_defined_for_str_mode), mode);
}
}
Expand Down