Patch 8.2.4959

7 views
Skip to first unread message

Bram Moolenaar

unread,
May 15, 2022, 9:50:51 AM5/15/22
to vim...@googlegroups.com

Patch 8.2.4959
Problem: Using NULL regexp program.
Solution: Check for regexp program becoming NULL in more places.
Files: src/buffer.c, src/testdir/test_buffer.vim


*** ../vim-8.2.4958/src/buffer.c 2022-05-11 11:42:24.048585612 +0100
--- src/buffer.c 2022-05-15 14:48:02.490143778 +0100
***************
*** 2642,2654 ****
if (*p == '^' && !(attempt & 1)) // add/remove '^'
++p;
regmatch.regprog = vim_regcomp(p, magic_isset() ? RE_MAGIC : 0);
- if (regmatch.regprog == NULL)
- {
- vim_free(pat);
- return -1;
- }

FOR_ALL_BUFS_FROM_LAST(buf)
if (buf->b_p_bl == find_listed
#ifdef FEAT_DIFF
&& (!diffmode || diff_mode_buf(buf))
--- 2642,2656 ----
if (*p == '^' && !(attempt & 1)) // add/remove '^'
++p;
regmatch.regprog = vim_regcomp(p, magic_isset() ? RE_MAGIC : 0);

FOR_ALL_BUFS_FROM_LAST(buf)
+ {
+ if (regmatch.regprog == NULL)
+ {
+ // invalid pattern, possibly after switching engine
+ vim_free(pat);
+ return -1;
+ }
if (buf->b_p_bl == find_listed
#ifdef FEAT_DIFF
&& (!diffmode || diff_mode_buf(buf))
***************
*** 2674,2679 ****
--- 2676,2682 ----
}
match = buf->b_fnum; // remember first match
}
+ }

vim_regfree(regmatch.regprog);
if (match >= 0) // found one match
***************
*** 2766,2777 ****
if (attempt > 0 && patc == pat)
break; // there was no anchor, no need to try again
regmatch.regprog = vim_regcomp(patc + attempt * 11, RE_MAGIC);
- if (regmatch.regprog == NULL)
- {
- if (patc != pat)
- vim_free(patc);
- return FAIL;
- }
}

// round == 1: Count the matches.
--- 2769,2774 ----
***************
*** 2792,2798 ****
--- 2789,2804 ----
#endif

if (!fuzzy)
+ {
+ if (regmatch.regprog == NULL)
+ {
+ // invalid pattern, possibly after recompiling
+ if (patc != pat)
+ vim_free(patc);
+ return FAIL;
+ }
p = buflist_match(&regmatch, buf, p_wic);
+ }
else
{
p = NULL;
***************
*** 2921,2926 ****
--- 2927,2933 ----

/*
* Check for a match on the file name for buffer "buf" with regprog "prog".
+ * Note that rmp->regprog may become NULL when switching regexp engine.
*/
static char_u *
buflist_match(
***************
*** 2939,2945 ****
}

/*
! * Try matching the regexp in "prog" with file name "name".
* Return "name" when there is a match, NULL when not.
*/
static char_u *
--- 2946,2953 ----
}

/*
! * Try matching the regexp in "rmp->regprog" with file name "name".
! * Note that rmp->regprog may become NULL when switching regexp engine.
* Return "name" when there is a match, NULL when not.
*/
static char_u *
***************
*** 2951,2957 ****
char_u *match = NULL;
char_u *p;

! if (name != NULL)
{
// Ignore case when 'fileignorecase' or the argument is set.
rmp->rm_ic = p_fic || ignore_case;
--- 2959,2966 ----
char_u *match = NULL;
char_u *p;

! // extra check for valid arguments
! if (name != NULL && rmp->regprog != NULL)
{
// Ignore case when 'fileignorecase' or the argument is set.
rmp->rm_ic = p_fic || ignore_case;
*** ../vim-8.2.4958/src/testdir/test_buffer.vim 2022-05-11 11:42:24.052585610 +0100
--- src/testdir/test_buffer.vim 2022-05-15 14:45:19.350273994 +0100
***************
*** 419,424 ****
--- 419,430 ----
vsplit 00000000000000000000000000
silent! buf [0--]\&\zs*\zs*e
bwipe!
+
+ " similar case with different code path
+ split 0
+ edit ÿ
+ silent! buf [0--]\&\zs*\zs*0
+ bwipe!
endfunc

" Test for the 'maxmem' and 'maxmemtot' options
*** ../vim-8.2.4958/src/version.c 2022-05-15 13:59:08.704167482 +0100
--- src/version.c 2022-05-15 14:49:14.386086360 +0100
***************
*** 748,749 ****
--- 748,751 ----
{ /* Add new patch number below this line */
+ /**/
+ 4959,
/**/

--
$ echo pizza > /dev/oven

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages