patch 9.1.0644: Unnecessary STRLEN() when applying mapping Commit: https://github.com/vim/vim/commit/74011dc1fa7bca6c901937173a42e0edce68e080 Author: zeertzjq <zeert...@outlook.com> Date: Tue Jul 30 19:17:56 2024 +0200
patch 9.1.0644: Unnecessary STRLEN() when applying mapping Problem: Unnecessary STRLEN() when applying mapping. (after v9.1.0642) Solution: Use m_keylen and vim_strnsave(). (zeertzjq) closes: #15394 Signed-off-by: zeertzjq <zeert...@outlook.com> Signed-off-by: Christian Brabandt <c...@256bit.org> diff --git a/src/getchar.c b/src/getchar.c index 54222ec30..29323fa32 100644 --- a/src/getchar.c +++ b/src/getchar.c @@ -3157,6 +3157,7 @@ handle_mapping( int save_m_silent; char_u *save_m_keys; char_u *save_alt_m_keys; + int save_alt_m_keylen; #else # define save_m_noremap mp->m_noremap # define save_m_silent mp->m_silent @@ -3206,6 +3207,7 @@ handle_mapping( save_m_silent = mp->m_silent; save_m_keys = NULL; // only saved when needed save_alt_m_keys = NULL; // only saved when needed + save_alt_m_keylen = mp->m_alt != NULL ? mp->m_alt->m_keylen : 0; /* * Handle ":map <expr>": evaluate the {rhs} as an expression. Also @@ -3222,9 +3224,10 @@ handle_mapping( vgetc_busy = 0; may_garbage_collect = FALSE; - save_m_keys = vim_strsave(mp->m_keys); + save_m_keys = vim_strnsave(mp->m_keys, (size_t)mp->m_keylen); save_alt_m_keys = mp->m_alt != NULL - ? vim_strsave(mp->m_alt->m_keys) : NULL; + ? vim_strnsave(mp->m_alt->m_keys, + (size_t)save_alt_m_keylen) : NULL; map_str = eval_map_expr(mp, NUL); // The mapping may do anything, but we expect it to take care of @@ -3287,12 +3290,12 @@ handle_mapping( && STRNCMP(map_str, save_m_keys, (size_t)keylen) == 0) || (save_alt_m_keys != NULL && STRNCMP(map_str, save_alt_m_keys, - STRLEN(save_alt_m_keys)) == 0) : + (size_t)save_alt_m_keylen) == 0) : #endif STRNCMP(map_str, mp->m_keys, (size_t)keylen) == 0 || (mp->m_alt != NULL && STRNCMP(map_str, mp->m_alt->m_keys, - STRLEN(mp->m_alt->m_keys)) == 0)) + (size_t)mp->m_alt->m_keylen) == 0)) noremap = REMAP_SKIP; else noremap = REMAP_YES; diff --git a/src/testdir/test_mapping.vim b/src/testdir/test_mapping.vim index 654a6734e..064f8ac25 100644 --- a/src/testdir/test_mapping.vim +++ b/src/testdir/test_mapping.vim @@ -1789,11 +1789,11 @@ func Test_map_rhs_starts_with_lhs() endif let @a = 'foo' - call feedkeys("S\<C-R>a", 'tx') + call assert_nobeep('call feedkeys("S\<C-R>a", "tx")') call assert_equal('foo', getline('.')) let @a = 'bar' - call feedkeys("S\<*C-R>a", 'tx') + call assert_nobeep('call feedkeys("S\<*C-R>a", "tx")') call assert_equal('bar', getline('.')) endfor endfor diff --git a/src/version.c b/src/version.c index bfcb7bf8e..a2662861e 100644 --- a/src/version.c +++ b/src/version.c @@ -704,6 +704,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 644, /**/ 643, /**/ -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_dev/E1sYqfk-003wPL-Dh%40256bit.org.