]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0438: Wrong Ex command executed when :g uses '?' as delimiter v9.1.0438
authorzeertzjq <zeertzjq@outlook.com>
Fri, 24 May 2024 05:37:36 +0000 (07:37 +0200)
committerChristian Brabandt <cb@256bit.org>
Fri, 24 May 2024 05:37:36 +0000 (07:37 +0200)
Problem:  Wrong Ex command executed when :g uses '?' as delimiter and
          pattern contains escaped '?'.
Solution: Don't use "*newp" when it's not allocated (zeertzjq).

closes: #14837

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/regexp.c
src/testdir/test_global.vim
src/testdir/test_substitute.vim
src/version.c

index 147452aae27bea40c2cd1a2eae080305dd7831b7..ff201d9ffee18aeef10b8746d4d0c0331f7490e7 100644 (file)
@@ -620,7 +620,7 @@ skip_regexp_ex(
 {
     magic_T    mymagic;
     char_u     *p = startp;
-    size_t     startplen = STRLEN(startp);
+    size_t     startplen = 0;
 
     if (magic)
        mymagic = MAGIC_ON;
@@ -644,16 +644,21 @@ skip_regexp_ex(
            if (dirc == '?' && newp != NULL && p[1] == '?')
            {
                // change "\?" to "?", make a copy first.
+               if (startplen == 0)
+                   startplen = STRLEN(startp);
                if (*newp == NULL)
                {
                    *newp = vim_strnsave(startp, startplen);
                    if (*newp != NULL)
+                   {
                        p = *newp + (p - startp);
+                       startp = *newp;
+                   }
                }
                if (dropped != NULL)
                    ++*dropped;
                if (*newp != NULL)
-                   mch_memmove(p, p + 1, (startplen - ((p + 1) - *newp)) + 1);
+                   mch_memmove(p, p + 1, startplen - ((p + 1) - startp) + 1);
                else
                    ++p;
            }
index 34857b25554131cac21309bde1e3a8f70728581d..0f72c3cf80cd733a8bf08a0a65045cfa9d616cf9 100644 (file)
@@ -116,7 +116,16 @@ func Test_global_newline()
   close!
 endfunc
 
-func Test_wrong_delimiter()
+" Test :g with ? as delimiter.
+func Test_global_question_delimiter()
+  new
+  call setline(1, ['aaaaa', 'b?bbb', 'ccccc', 'ddd?d', 'eeeee'])
+  g?\??delete
+  call assert_equal(['aaaaa', 'ccccc', 'eeeee'], getline(1, '$'))
+  bwipe!
+endfunc
+
+func Test_global_wrong_delimiter()
   call assert_fails('g x^bxd', 'E146:')
 endfunc
 
index a2367cd233d2522a241f5edcc2bab4b7137b082c..afdc104d7c58c5bb13a5c3c6f38d8029528256e6 100644 (file)
@@ -174,8 +174,8 @@ func Test_substitute_repeat()
   bwipe!
 endfunc
 
-" Test :s with ? as separator.
-func Test_substitute_question_separator()
+" Test :s with ? as delimiter.
+func Test_substitute_question_delimiter()
   new
   call setline(1, '??:??')
   %s?\?\??!!?g
index 7188cbd88815c35c7e432a3574076d4dfa28e1f5..ac1a1f4f3f0073b8843b92149b7257bb874e6c51 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    438,
 /**/
     437,
 /**/