mirror of
https://github.com/neovim/neovim.git
synced 2024-12-31 17:13:26 -07:00
vim-patch:9.1.0365: Crash when typing many keys with D- modifier (#28464)
Problem: Crash when typing many keys with D- modifier (after 9.1.0227).
Solution: Don't treat a 0x80 byte inside a special sequence as the start
of a special sequence (zeertzjq).
closes: vim/vim#14613
6b13e3d4e4
This commit is contained in:
parent
cb2b5e2780
commit
d0ab67410c
@ -66,12 +66,11 @@
|
|||||||
|
|
||||||
/// State for adding bytes to a recording or 'showcmd'.
|
/// State for adding bytes to a recording or 'showcmd'.
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int prev_c;
|
|
||||||
uint8_t buf[MB_MAXBYTES * 3 + 4];
|
uint8_t buf[MB_MAXBYTES * 3 + 4];
|
||||||
|
int prev_c;
|
||||||
size_t buflen;
|
size_t buflen;
|
||||||
unsigned pending;
|
unsigned pending_special;
|
||||||
bool in_special;
|
unsigned pending_mbyte;
|
||||||
bool in_mbyte;
|
|
||||||
} gotchars_state_T;
|
} gotchars_state_T;
|
||||||
|
|
||||||
/// Index in scriptin
|
/// Index in scriptin
|
||||||
@ -1129,27 +1128,25 @@ static bool gotchars_add_byte(gotchars_state_T *state, uint8_t byte)
|
|||||||
{
|
{
|
||||||
int c = state->buf[state->buflen++] = byte;
|
int c = state->buf[state->buflen++] = byte;
|
||||||
bool retval = false;
|
bool retval = false;
|
||||||
|
const bool in_special = state->pending_special > 0;
|
||||||
|
const bool in_mbyte = state->pending_mbyte > 0;
|
||||||
|
|
||||||
if (state->pending > 0) {
|
if (in_special) {
|
||||||
state->pending--;
|
state->pending_special--;
|
||||||
|
} else if (c == K_SPECIAL) {
|
||||||
|
// When receiving a special key sequence, store it until we have all
|
||||||
|
// the bytes and we can decide what to do with it.
|
||||||
|
state->pending_special = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// When receiving a special key sequence, store it until we have all
|
if (state->pending_special > 0) {
|
||||||
// the bytes and we can decide what to do with it.
|
|
||||||
if ((state->pending == 0 || state->in_mbyte) && c == K_SPECIAL) {
|
|
||||||
state->pending += 2;
|
|
||||||
if (!state->in_mbyte) {
|
|
||||||
state->in_special = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state->pending > 0) {
|
|
||||||
goto ret_false;
|
goto ret_false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!state->in_mbyte) {
|
if (in_mbyte) {
|
||||||
if (state->in_special) {
|
state->pending_mbyte--;
|
||||||
state->in_special = false;
|
} else {
|
||||||
|
if (in_special) {
|
||||||
if (state->prev_c == KS_MODIFIER) {
|
if (state->prev_c == KS_MODIFIER) {
|
||||||
// When receiving a modifier, wait for the modified key.
|
// When receiving a modifier, wait for the modified key.
|
||||||
goto ret_false;
|
goto ret_false;
|
||||||
@ -1159,14 +1156,11 @@ static bool gotchars_add_byte(gotchars_state_T *state, uint8_t byte)
|
|||||||
// When receiving a multibyte character, store it until we have all
|
// When receiving a multibyte character, store it until we have all
|
||||||
// the bytes, so that it won't be split between two buffer blocks,
|
// the bytes, so that it won't be split between two buffer blocks,
|
||||||
// and delete_buff_tail() will work properly.
|
// and delete_buff_tail() will work properly.
|
||||||
state->pending = MB_BYTE2LEN_CHECK(c) - 1;
|
state->pending_mbyte = MB_BYTE2LEN_CHECK(c) - 1;
|
||||||
if (state->pending > 0) {
|
}
|
||||||
state->in_mbyte = true;
|
|
||||||
goto ret_false;
|
if (state->pending_mbyte > 0) {
|
||||||
}
|
goto ret_false;
|
||||||
} else {
|
|
||||||
// Stored all bytes of a multibyte character.
|
|
||||||
state->in_mbyte = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
retval = true;
|
retval = true;
|
||||||
|
@ -236,21 +236,25 @@ func Test_map_meta_multibyte()
|
|||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_map_super_quotes()
|
func Test_map_super_quotes()
|
||||||
if has('gui_gtk') || has('gui_gtk3') || has("macos")
|
if "\<D-j>"[-1:] == '>'
|
||||||
imap <D-"> foo
|
throw 'Skipped: <D- modifier not supported'
|
||||||
call feedkeys("Go-\<*D-\">-\<Esc>", "xt")
|
|
||||||
call assert_equal("-foo-", getline('$'))
|
|
||||||
set nomodified
|
|
||||||
iunmap <D-">
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
imap <D-"> foo
|
||||||
|
call feedkeys("Go-\<*D-\">-\<Esc>", "xt")
|
||||||
|
call assert_equal("-foo-", getline('$'))
|
||||||
|
set nomodified
|
||||||
|
iunmap <D-">
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_map_super_multibyte()
|
func Test_map_super_multibyte()
|
||||||
if has('gui_gtk') || has('gui_gtk3') || has("macos")
|
if "\<D-j>"[-1:] == '>'
|
||||||
imap <D-á> foo
|
throw 'Skipped: <D- modifier not supported'
|
||||||
call assert_match('i <D-á>\s*foo', execute('imap'))
|
|
||||||
iunmap <D-á>
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
imap <D-á> foo
|
||||||
|
call assert_match('i <D-á>\s*foo', execute('imap'))
|
||||||
|
iunmap <D-á>
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_abbr_after_line_join()
|
func Test_abbr_after_line_join()
|
||||||
|
@ -266,6 +266,19 @@ func Test_zz_recording_with_select_mode_utf8_gui()
|
|||||||
call Run_test_recording_with_select_mode_utf8()
|
call Run_test_recording_with_select_mode_utf8()
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_recording_with_super_mod()
|
||||||
|
if "\<D-j>"[-1:] == '>'
|
||||||
|
throw 'Skipped: <D- modifier not supported'
|
||||||
|
endif
|
||||||
|
|
||||||
|
nnoremap <D-j> <Ignore>
|
||||||
|
let s = repeat("\<D-j>", 1000)
|
||||||
|
" This used to crash Vim
|
||||||
|
call feedkeys($'qr{s}q', 'tx')
|
||||||
|
call assert_equal(s, @r)
|
||||||
|
nunmap <D-j>
|
||||||
|
endfunc
|
||||||
|
|
||||||
" Test for executing the last used register (@)
|
" Test for executing the last used register (@)
|
||||||
func Test_last_used_exec_reg()
|
func Test_last_used_exec_reg()
|
||||||
" Test for the @: command
|
" Test for the @: command
|
||||||
|
Loading…
Reference in New Issue
Block a user