summaryrefslogtreecommitdiffstats
path: root/src/ex_cmds.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ex_cmds.c')
-rw-r--r--src/ex_cmds.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index 5c34e8645d..8143c24060 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -3750,6 +3750,7 @@ ex_substitute(exarg_T *eap)
int save_do_all; // remember user specified 'g' flag
int save_do_ask; // remember user specified 'c' flag
char_u *pat = NULL, *sub = NULL; // init for GCC
+ size_t patlen = 0;
int delimiter;
int sublen;
int got_quit = FALSE;
@@ -3823,6 +3824,7 @@ ex_substitute(exarg_T *eap)
if (*cmd != '&')
which_pat = RE_SEARCH; // use last '/' pattern
pat = (char_u *)""; // empty search pattern
+ patlen = 0;
delimiter = *cmd++; // remember delimiter character
}
else // find the end of the regexp
@@ -3830,6 +3832,7 @@ ex_substitute(exarg_T *eap)
which_pat = RE_LAST; // use last used regexp
delimiter = *cmd++; // remember delimiter character
pat = cmd; // remember start of search pat
+ patlen = STRLEN(pat);
cmd = skip_regexp_ex(cmd, delimiter, magic_isset(),
&eap->arg, NULL, NULL);
if (cmd[0] == delimiter) // end delimiter found
@@ -3883,6 +3886,7 @@ ex_substitute(exarg_T *eap)
return;
}
pat = NULL; // search_regcomp() will use previous pattern
+ patlen = 0;
sub = vim_strsave(old_sub);
// Vi compatibility quirk: repeating with ":s" keeps the cursor in the
@@ -3929,9 +3933,9 @@ ex_substitute(exarg_T *eap)
}
if ((cmdmod.cmod_flags & CMOD_KEEPPATTERNS) == 0)
- save_re_pat(RE_SUBST, pat, magic_isset());
+ save_re_pat(RE_SUBST, pat, patlen, magic_isset());
// put pattern in history
- add_to_history(HIST_SEARCH, pat, TRUE, NUL);
+ add_to_history(HIST_SEARCH, pat, patlen, TRUE, NUL);
vim_free(sub);
return;
@@ -4066,7 +4070,7 @@ ex_substitute(exarg_T *eap)
return;
}
- if (search_regcomp(pat, NULL, RE_SUBST, which_pat, SEARCH_HIS, &regmatch) == FAIL)
+ if (search_regcomp(pat, patlen, NULL, RE_SUBST, which_pat, SEARCH_HIS, &regmatch) == FAIL)
{
if (subflags.do_error)
emsg(_(e_invalid_command));
@@ -5104,6 +5108,7 @@ ex_global(exarg_T *eap)
char_u delim; // delimiter, normally '/'
char_u *pat;
+ size_t patlen;
char_u *used_pat;
regmmatch_T regmatch;
int match;
@@ -5150,6 +5155,7 @@ ex_global(exarg_T *eap)
which_pat = RE_SEARCH; // use previous search pattern
++cmd;
pat = (char_u *)"";
+ patlen = 0;
}
else if (*cmd == NUL)
{
@@ -5165,12 +5171,13 @@ ex_global(exarg_T *eap)
delim = *cmd; // get the delimiter
++cmd; // skip delimiter if there is one
pat = cmd; // remember start of pattern
+ patlen = STRLEN(pat);
cmd = skip_regexp_ex(cmd, delim, magic_isset(), &eap->arg, NULL, NULL);
if (cmd[0] == delim) // end delimiter found
*cmd++ = NUL; // replace it with a NUL
}
- if (search_regcomp(pat, &used_pat, RE_BOTH, which_pat, SEARCH_HIS,
+ if (search_regcomp(pat, patlen, &used_pat, RE_BOTH, which_pat, SEARCH_HIS,
&regmatch) == FAIL)
{
emsg(_(e_invalid_command));