neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit e135adcb8c4f32332ba87ea6681f41330b909e1c
parent b08cf73be959397b5715395f1465fb76a76a6a05
Author: zeertzjq <zeertzjq@outlook.com>
Date:   Tue,  5 Apr 2022 09:00:48 +0800

vim-patch:8.2.4687: "vimgrep /%v/ *" may cause a crash (#17995)

Problem:    "vimgrep /\%v/ *" may cause a crash.
Solution:   When compiling the pattern with the old engine fails, restore the
            regprog of the new engine instead of leaving it NULL.
            (closes vim/vim#10079)
https://github.com/vim/vim/commit/e8a4c0d91f89544e4f94b7bd612b5fb780944c33
Diffstat:
Msrc/nvim/regexp.c | 11+++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c @@ -2504,7 +2504,8 @@ long vim_regexec_multi( char_u *pat = vim_strsave(((nfa_regprog_T *)rmp->regprog)->pattern); p_re = BACKTRACKING_ENGINE; - vim_regfree(rmp->regprog); + regprog_T *prev_prog = rmp->regprog; + report_re_switch(pat); // checking for \z misuse was already done when compiling for NFA, // allow all here @@ -2512,7 +2513,13 @@ long vim_regexec_multi( rmp->regprog = vim_regcomp(pat, re_flags); reg_do_extmatch = 0; - if (rmp->regprog != NULL) { + if (rmp->regprog == NULL) { + // Somehow compiling the pattern failed now, put back the + // previous one to avoid "regprog" becoming NULL. + rmp->regprog = prev_prog; + } else { + vim_regfree(prev_prog); + rmp->regprog->re_in_use = true; result = rmp->regprog->engine->regexec_multi(rmp, win, buf, lnum, col, tm, timed_out);