To: vim_dev@googlegroups.com Subject: Patch 8.2.4833 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.4833 Problem: Failure of mapping not checked for. Solution: Check return value of ins_typebuf(). (closes #10299) Files: src/getchar.c, src/term.c, src/testdir/test_termcodes.vim *** ../vim-8.2.4832/src/getchar.c 2022-04-26 22:11:35.535293814 +0100 --- src/getchar.c 2022-04-27 11:56:49.593000921 +0100 *************** *** 2363,2369 **** * into just a key, apply that. * 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. */ static int check_simplify_modifier(int max_offset) --- 2363,2369 ---- * into just a key, apply that. * Check from typebuf.tb_buf[typebuf.tb_off] to typebuf.tb_buf[typebuf.tb_off * + "max_offset"]. ! * Return the length of the replaced bytes, 0 if nothing changed, -1 for error. */ static int check_simplify_modifier(int max_offset) *************** *** 2397,2403 **** vgetc_char = c; vgetc_mod_mask = tp[2]; } ! len = mb_char2bytes(new_c, new_string); if (modifier == 0) { if (put_string_in_typebuf(offset, 4, new_string, len, --- 2397,2411 ---- vgetc_char = c; vgetc_mod_mask = tp[2]; } ! if (IS_SPECIAL(new_c)) ! { ! new_string[0] = K_SPECIAL; ! new_string[1] = K_SECOND(new_c); ! new_string[2] = K_THIRD(new_c); ! len = 3; ! } ! else ! len = mb_char2bytes(new_c, new_string); if (modifier == 0) { if (put_string_in_typebuf(offset, 4, new_string, len, *************** *** 2424,2429 **** --- 2432,2438 ---- * - 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 * typeahead. + * - On failure (out of memory) return map_result_fail. */ static int handle_mapping( *************** *** 2706,2712 **** --- 2715,2726 ---- // If no termcode matched, try to include the modifier into the // key. This is for when modifyOtherKeys is working. if (keylen == 0 && !no_reduce_keys) + { keylen = check_simplify_modifier(max_mlen + 1); + if (keylen < 0) + // ins_typebuf() failed + return map_result_fail; + } // When getting a partial match, but the last characters were not // typed, don't wait for a typed character to complete the *** ../vim-8.2.4832/src/term.c 2022-04-26 22:11:35.539293808 +0100 --- src/term.c 2022-04-27 11:57:16.881002610 +0100 *************** *** 4531,4537 **** del_typebuf(-extra, offset); else if (extra > 0) // insert the extra space we need ! ins_typebuf(string + slen, REMAP_YES, offset, FALSE, FALSE); // Careful: del_typebuf() and ins_typebuf() may have reallocated // typebuf.tb_buf[]! --- 4531,4539 ---- del_typebuf(-extra, offset); else if (extra > 0) // insert the extra space we need ! if (ins_typebuf(string + slen, REMAP_YES, offset, FALSE, FALSE) ! == FAIL) ! return FAIL; // Careful: del_typebuf() and ins_typebuf() may have reallocated // typebuf.tb_buf[]! *** ../vim-8.2.4832/src/testdir/test_termcodes.vim 2022-04-26 12:51:01.074682254 +0100 --- src/testdir/test_termcodes.vim 2022-04-27 11:53:33.680943956 +0100 *************** *** 2439,2446 **** func Test_simplify_ctrl_at() " feeding unsimplified CTRL-@ should still trigger i_CTRL-@ ! call feedkeys("ifoo\A\<*C-@>", 'xt') ! call assert_equal('foofoo', getline(1)) endfunc --- 2439,2447 ---- func Test_simplify_ctrl_at() " feeding unsimplified CTRL-@ should still trigger i_CTRL-@ ! call feedkeys("ifoo\A\<*C-@>x", 'xt') ! call assert_equal('foofo', getline(1)) ! bw! endfunc *** ../vim-8.2.4832/src/version.c 2022-04-26 22:11:35.539293808 +0100 --- src/version.c 2022-04-27 11:55:17.216984674 +0100 *************** *** 748,749 **** --- 748,751 ---- { /* Add new patch number below this line */ + /**/ + 4833, /**/ -- hundred-and-one symptoms of being an internet addict: 70. ISDN lines are added to your house on a hourly basis /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///