mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:8.2.4833: failure of mapping not checked for
Problem: Failure of mapping not checked for.
Solution: Check return value of ins_typebuf(). (closes vim/vim#10299)
12e21e387b
This commit is contained in:
parent
bf065d9bb6
commit
1d97781dc5
@ -1761,7 +1761,9 @@ static int put_string_in_typebuf(int offset, int slen, char_u *string, int new_s
|
|||||||
del_typebuf(-extra, offset);
|
del_typebuf(-extra, offset);
|
||||||
} else if (extra > 0) {
|
} else if (extra > 0) {
|
||||||
// insert the extra space we need
|
// insert the extra space we need
|
||||||
ins_typebuf(string + slen, REMAP_YES, offset, false, false);
|
if (ins_typebuf(string + slen, REMAP_YES, offset, false, false) == FAIL) {
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Careful: del_typebuf() and ins_typebuf() may have reallocated
|
// Careful: del_typebuf() and ins_typebuf() may have reallocated
|
||||||
// typebuf.tb_buf[]!
|
// typebuf.tb_buf[]!
|
||||||
@ -1772,7 +1774,7 @@ static int put_string_in_typebuf(int offset, int slen, char_u *string, int new_s
|
|||||||
/// Check if typebuf.tb_buf[] contains a modifer plus key that can be changed
|
/// Check if typebuf.tb_buf[] contains a modifer plus key that can be changed
|
||||||
/// into just a key, apply that.
|
/// into just a key, apply that.
|
||||||
/// Check from typebuf.tb_buf[typebuf.tb_off] to typebuf.tb_buf[typebuf.tb_off + "max_offset"].
|
/// Check from typebuf.tb_buf[typebuf.tb_off] to typebuf.tb_buf[typebuf.tb_off + "max_offset"].
|
||||||
/// @return the length of the replaced bytes, zero if nothing changed.
|
/// @return the length of the replaced bytes, 0 if nothing changed, -1 for error.
|
||||||
static int check_simplify_modifier(int max_offset)
|
static int check_simplify_modifier(int max_offset)
|
||||||
{
|
{
|
||||||
for (int offset = 0; offset < max_offset; offset++) {
|
for (int offset = 0; offset < max_offset; offset++) {
|
||||||
@ -1796,7 +1798,15 @@ static int check_simplify_modifier(int max_offset)
|
|||||||
vgetc_mod_mask = tp[2];
|
vgetc_mod_mask = tp[2];
|
||||||
}
|
}
|
||||||
char_u new_string[MB_MAXBYTES];
|
char_u new_string[MB_MAXBYTES];
|
||||||
int len = utf_char2bytes(new_c, new_string);
|
int len;
|
||||||
|
if (IS_SPECIAL(new_c)) {
|
||||||
|
new_string[0] = K_SPECIAL;
|
||||||
|
new_string[1] = (char_u)K_SECOND(new_c);
|
||||||
|
new_string[2] = (char_u)K_THIRD(new_c);
|
||||||
|
len = 3;
|
||||||
|
} else {
|
||||||
|
len = utf_char2bytes(new_c, new_string);
|
||||||
|
}
|
||||||
if (modifier == 0) {
|
if (modifier == 0) {
|
||||||
if (put_string_in_typebuf(offset, 4, new_string, len) == FAIL) {
|
if (put_string_in_typebuf(offset, 4, new_string, len) == FAIL) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -1819,6 +1829,7 @@ static int check_simplify_modifier(int max_offset)
|
|||||||
/// - When nothing mapped and typeahead has a character: return map_result_get.
|
/// - When nothing mapped and typeahead has a character: return map_result_get.
|
||||||
/// - When there is no match yet, return map_result_nomatch, need to get more
|
/// - When there is no match yet, return map_result_nomatch, need to get more
|
||||||
/// typeahead.
|
/// typeahead.
|
||||||
|
/// - On failure (out of memory) return map_result_fail.
|
||||||
static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
|
static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
|
||||||
{
|
{
|
||||||
mapblock_T *mp = NULL;
|
mapblock_T *mp = NULL;
|
||||||
@ -2032,7 +2043,10 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
|
|||||||
} else if (keylen != KEYLEN_PART_KEY) {
|
} else if (keylen != KEYLEN_PART_KEY) {
|
||||||
// Try to include the modifier into the key.
|
// Try to include the modifier into the key.
|
||||||
keylen = check_simplify_modifier(max_mlen + 1);
|
keylen = check_simplify_modifier(max_mlen + 1);
|
||||||
assert(keylen >= 0);
|
if (keylen < 0) {
|
||||||
|
// ins_typebuf() failed
|
||||||
|
return map_result_fail;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
keylen = 0;
|
keylen = 0;
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
|
|
||||||
func Test_simplify_ctrl_at()
|
func Test_simplify_ctrl_at()
|
||||||
" feeding unsimplified CTRL-@ should still trigger i_CTRL-@
|
" feeding unsimplified CTRL-@ should still trigger i_CTRL-@
|
||||||
call feedkeys("ifoo\<Esc>A\<*C-@>", 'xt')
|
call feedkeys("ifoo\<Esc>A\<*C-@>x", 'xt')
|
||||||
call assert_equal('foofoo', getline(1))
|
call assert_equal('foofo', getline(1))
|
||||||
|
bw!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user