summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-05-24 07:37:36 +0200
committerChristian Brabandt <cb@256bit.org>2024-05-24 07:37:36 +0200
commit3074137542961ce7b3b65c14ebde75f13f5e6147 (patch)
tree12cad0d7a73be217e53beac7b89e20896ba732e7
parent22ac941208fcb2c63ad172c6cf0b39b077b5b682 (diff)
patch 9.1.0438: Wrong Ex command executed when :g uses '?' as delimiterv9.1.0438
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>
-rw-r--r--src/regexp.c9
-rw-r--r--src/testdir/test_global.vim11
-rw-r--r--src/testdir/test_substitute.vim4
-rw-r--r--src/version.c2
4 files changed, 21 insertions, 5 deletions
diff --git a/src/regexp.c b/src/regexp.c
index 147452aae2..ff201d9ffe 100644
--- a/src/regexp.c
+++ b/src/regexp.c
@@ -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;
}
diff --git a/src/testdir/test_global.vim b/src/testdir/test_global.vim
index 34857b2555..0f72c3cf80 100644
--- a/src/testdir/test_global.vim
+++ b/src/testdir/test_global.vim
@@ -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
diff --git a/src/testdir/test_substitute.vim b/src/testdir/test_substitute.vim
index a2367cd233..afdc104d7c 100644
--- a/src/testdir/test_substitute.vim
+++ b/src/testdir/test_substitute.vim
@@ -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
diff --git a/src/version.c b/src/version.c
index 7188cbd888..ac1a1f4f3f 100644
--- a/src/version.c
+++ b/src/version.c
@@ -705,6 +705,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 438,
+/**/
437,
/**/
436,