mirror of
https://github.com/neovim/neovim.git
synced 2025-09-17 16:58:17 +00:00
No OOM in msg_show_console_dialog()
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
#include "nvim/eval.h"
|
#include "nvim/eval.h"
|
||||||
#include "nvim/ex_eval.h"
|
#include "nvim/ex_eval.h"
|
||||||
#include "nvim/fileio.h"
|
#include "nvim/fileio.h"
|
||||||
|
#include "nvim/func_attr.h"
|
||||||
#include "nvim/getchar.h"
|
#include "nvim/getchar.h"
|
||||||
#include "nvim/mbyte.h"
|
#include "nvim/mbyte.h"
|
||||||
#include "nvim/memory.h"
|
#include "nvim/memory.h"
|
||||||
@@ -2710,51 +2711,49 @@ do_dialog (
|
|||||||
++no_wait_return;
|
++no_wait_return;
|
||||||
hotkeys = msg_show_console_dialog(message, buttons, dfltbutton);
|
hotkeys = msg_show_console_dialog(message, buttons, dfltbutton);
|
||||||
|
|
||||||
if (hotkeys != NULL) {
|
for (;; ) {
|
||||||
for (;; ) {
|
/* Get a typed character directly from the user. */
|
||||||
/* Get a typed character directly from the user. */
|
c = get_keystroke();
|
||||||
c = get_keystroke();
|
switch (c) {
|
||||||
switch (c) {
|
case CAR: /* User accepts default option */
|
||||||
case CAR: /* User accepts default option */
|
case NL:
|
||||||
case NL:
|
retval = dfltbutton;
|
||||||
retval = dfltbutton;
|
|
||||||
break;
|
|
||||||
case Ctrl_C: /* User aborts/cancels */
|
|
||||||
case ESC:
|
|
||||||
retval = 0;
|
|
||||||
break;
|
|
||||||
default: /* Could be a hotkey? */
|
|
||||||
if (c < 0) /* special keys are ignored here */
|
|
||||||
continue;
|
|
||||||
if (c == ':' && ex_cmd) {
|
|
||||||
retval = dfltbutton;
|
|
||||||
ins_char_typebuf(':');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Make the character lowercase, as chars in "hotkeys" are. */
|
|
||||||
c = vim_tolower(c);
|
|
||||||
retval = 1;
|
|
||||||
for (i = 0; hotkeys[i]; ++i) {
|
|
||||||
if (has_mbyte) {
|
|
||||||
if ((*mb_ptr2char)(hotkeys + i) == c)
|
|
||||||
break;
|
|
||||||
i += (*mb_ptr2len)(hotkeys + i) - 1;
|
|
||||||
} else if (hotkeys[i] == c)
|
|
||||||
break;
|
|
||||||
++retval;
|
|
||||||
}
|
|
||||||
if (hotkeys[i])
|
|
||||||
break;
|
|
||||||
/* No hotkey match, so keep waiting */
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
case Ctrl_C: /* User aborts/cancels */
|
||||||
|
case ESC:
|
||||||
|
retval = 0;
|
||||||
|
break;
|
||||||
|
default: /* Could be a hotkey? */
|
||||||
|
if (c < 0) /* special keys are ignored here */
|
||||||
|
continue;
|
||||||
|
if (c == ':' && ex_cmd) {
|
||||||
|
retval = dfltbutton;
|
||||||
|
ins_char_typebuf(':');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
free(hotkeys);
|
/* Make the character lowercase, as chars in "hotkeys" are. */
|
||||||
|
c = vim_tolower(c);
|
||||||
|
retval = 1;
|
||||||
|
for (i = 0; hotkeys[i]; ++i) {
|
||||||
|
if (has_mbyte) {
|
||||||
|
if ((*mb_ptr2char)(hotkeys + i) == c)
|
||||||
|
break;
|
||||||
|
i += (*mb_ptr2len)(hotkeys + i) - 1;
|
||||||
|
} else if (hotkeys[i] == c)
|
||||||
|
break;
|
||||||
|
++retval;
|
||||||
|
}
|
||||||
|
if (hotkeys[i])
|
||||||
|
break;
|
||||||
|
/* No hotkey match, so keep waiting */
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(hotkeys);
|
||||||
|
|
||||||
State = oldState;
|
State = oldState;
|
||||||
setmouse();
|
setmouse();
|
||||||
--no_wait_return;
|
--no_wait_return;
|
||||||
@@ -2871,6 +2870,7 @@ static char_u * console_dialog_alloc(const char_u *message,
|
|||||||
* Returns an allocated string with hotkeys, or NULL for error.
|
* Returns an allocated string with hotkeys, or NULL for error.
|
||||||
*/
|
*/
|
||||||
static char_u *msg_show_console_dialog(char_u *message, char_u *buttons, int dfltbutton)
|
static char_u *msg_show_console_dialog(char_u *message, char_u *buttons, int dfltbutton)
|
||||||
|
FUNC_ATTR_NONNULL_RET
|
||||||
{
|
{
|
||||||
bool has_hotkey[HAS_HOTKEY_LEN];
|
bool has_hotkey[HAS_HOTKEY_LEN];
|
||||||
char_u *hotk = console_dialog_alloc(message, buttons, has_hotkey);
|
char_u *hotk = console_dialog_alloc(message, buttons, has_hotkey);
|
||||||
|
Reference in New Issue
Block a user