]> granicus.if.org Git - vim/commitdiff
patch 8.2.3611: crash when using CTRL-W f without finding a file name v8.2.3611
authorBram Moolenaar <Bram@vim.org>
Wed, 17 Nov 2021 18:00:31 +0000 (18:00 +0000)
committerBram Moolenaar <Bram@vim.org>
Wed, 17 Nov 2021 18:00:31 +0000 (18:00 +0000)
Problem:    Crash when using CTRL-W f without finding a file name.
Solution:   Bail out when the file name length is zero.

src/findfile.c
src/normal.c
src/testdir/test_visual.vim
src/version.c

index b79b1d1dbf4a245011a224b3ccc8025ec30dd818..b4aed048ce3c7d15d3f927d92947e7ef40bdfbf7 100644 (file)
@@ -1735,6 +1735,9 @@ find_file_in_path_option(
     proc->pr_WindowPtr = (APTR)-1L;
 # endif
 
+    if (len == 0)
+       return NULL;
+
     if (first == TRUE)
     {
        // copy file name into NameBuff, expanding environment variables
@@ -2118,7 +2121,12 @@ find_file_name_in_path(
     int                c;
 # if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
     char_u     *tofree = NULL;
+# endif
 
+    if (len == 0)
+       return NULL;
+
+# if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
     if ((options & FNAME_INCL) && *curbuf->b_p_inex != NUL)
     {
        tofree = eval_includeexpr(ptr, len);
index 059baee90faabe790fb8d364b2ba78e16e7b8f2a..aab336a5fe90576328e9a90f4714b6be6d53e6d9 100644 (file)
@@ -3881,8 +3881,10 @@ get_visual_text(
            *pp = ml_get_pos(&VIsual);
            *lenp = curwin->w_cursor.col - VIsual.col + 1;
        }
-       if (has_mbyte)
-           // Correct the length to include the whole last character.
+       if (**pp == NUL)
+           *lenp = 0;
+       if (has_mbyte && *lenp > 0)
+           // Correct the length to include all bytes of the last character.
            *lenp += (*mb_ptr2len)(*pp + (*lenp - 1)) - 1;
     }
     reset_VIsual_and_resel();
index 20eb4b43e8e8854c3bac2089ac4d7da3eb772c6b..0c89dbb0103bcdaa7d5f519e43b4f20192683468 100644 (file)
@@ -1265,6 +1265,14 @@ func Test_visual_block_with_virtualedit()
   call delete('XTest_block')
 endfunc
 
+func Test_visual_block_ctrl_w_f()
+  " Emtpy block selected in new buffer should not result in an error.
+  au! BufNew foo sil norm \16\17f
+  edit foo
+
+  au! BufNew
+endfunc
+
 func Test_visual_reselect_with_count()
   " this was causing an illegal memory access
   let lines =<< trim END
index d301120079e6910dd29b59fc08a8a981aa0ae200..4251b03ea5ad368ebfd43b8fd468b1d044cd9d48 100644 (file)
@@ -757,6 +757,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3611,
 /**/
     3610,
 /**/