]> granicus.if.org Git - vim/commitdiff
patch 8.2.4833: failure of mapping not checked for v8.2.4833
authorzeertzjq <zeertzjq@outlook.com>
Wed, 27 Apr 2022 10:58:01 +0000 (11:58 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 27 Apr 2022 10:58:01 +0000 (11:58 +0100)
Problem:    Failure of mapping not checked for.
Solution:   Check return value of ins_typebuf(). (closes #10299)

src/getchar.c
src/term.c
src/testdir/test_termcodes.vim
src/version.c

index e208dd1a18444d2b68fd3e2a1878af2f3dab22ea..e6879c60d97572109a5b9d2dc5cfb1e83bb4e4e6 100644 (file)
@@ -2363,7 +2363,7 @@ at_ctrl_x_key(void)
  * 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.
+ * Return the length of the replaced bytes, 0 if nothing changed, -1 for error.
  */
     static int
 check_simplify_modifier(int max_offset)
@@ -2397,7 +2397,15 @@ check_simplify_modifier(int max_offset)
                    vgetc_char = c;
                    vgetc_mod_mask = tp[2];
                }
-               len = mb_char2bytes(new_c, new_string);
+               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,6 +2432,7 @@ check_simplify_modifier(int max_offset)
  * - 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,7 +2715,12 @@ handle_mapping(
            // 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
index 14cee6ac266d2f6d79a18d3864f27e08a7950bac..ee8be7f8fcb3cea16fb7b468289d9f83424996fd 100644 (file)
@@ -4531,7 +4531,9 @@ put_string_in_typebuf(
            del_typebuf(-extra, offset);
        else if (extra > 0)
            // 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
        // typebuf.tb_buf[]!
index ddbe707d10e65452faab59f517941dff91aa58d4..c9b0c7b735b67f3f400aff0f08982e4f81778584 100644 (file)
@@ -2439,8 +2439,9 @@ endfunc
 
 func Test_simplify_ctrl_at()
   " feeding unsimplified CTRL-@ should still trigger i_CTRL-@
-  call feedkeys("ifoo\<Esc>A\<*C-@>", 'xt')
-  call assert_equal('foofoo', getline(1))
+  call feedkeys("ifoo\<Esc>A\<*C-@>x", 'xt')
+  call assert_equal('foofo', getline(1))
+  bw!
 endfunc
 
 
index 115989cac48efc37d1c242430528e94c2503204c..a8f6671d9a87b8eb8de20f78103b4c44e3371963 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4833,
 /**/
     4832,
 /**/