0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

patch 8.2.4029: debugging NFA regexp my crash, cached indent may be wrong

Problem:    Debugging NFA regexp my crash, cached indent may be wrong.
Solution:   Fix some debug warnings in the NFA regexp code.  Make sure log_fd
            is set when used.  Fix breakindent and indent caching. (Christian
            Brabandt, closes #9482)
This commit is contained in:
Bram Moolenaar
2022-01-07 16:55:32 +00:00
parent cb1956d6f2
commit b2d85e3784
4 changed files with 76 additions and 45 deletions

View File

@@ -915,13 +915,15 @@ get_breakindent_win(
win_T *wp,
char_u *line) // start of the line
{
static int prev_indent = 0; // cached indent value
static long prev_ts = 0L; // cached tabstop value
static char_u *prev_line = NULL; // cached pointer to line
static int prev_indent = 0; // cached indent value
static long prev_ts = 0L; // cached tabstop value
static char_u *prev_line = NULL; // cached pointer to line
static varnumber_T prev_tick = 0; // changedtick of cached value
# ifdef FEAT_VARTABS
static int *prev_vts = NULL; // cached vartabs values
static int *prev_vts = NULL; // cached vartabs values
# endif
static int prev_list = 0; // cached list value
static int prev_listopt = 0; // cached w_p_briopt_list value
int bri = 0;
// window width minus window margin space, i.e. what rests for text
const int eff_wwidth = wp->w_width
@@ -929,9 +931,10 @@ get_breakindent_win(
&& (vim_strchr(p_cpo, CPO_NUMCOL) == NULL)
? number_width(wp) + 1 : 0);
// used cached indent, unless pointer or 'tabstop' changed
// used cached indent, unless line, 'tabstop' or briopt_list changed
if (prev_line != line || prev_ts != wp->w_buffer->b_p_ts
|| prev_tick != CHANGEDTICK(wp->w_buffer)
|| prev_listopt != wp->w_briopt_list
# ifdef FEAT_VARTABS
|| prev_vts != wp->w_buffer->b_p_vts_array
# endif
@@ -949,6 +952,28 @@ get_breakindent_win(
prev_indent = get_indent_str(line,
(int)wp->w_buffer->b_p_ts, wp->w_p_list);
# endif
prev_listopt = wp->w_briopt_list;
// add additional indent for numbered lists
if (wp->w_briopt_list != 0)
{
regmatch_T regmatch;
regmatch.regprog = vim_regcomp(curbuf->b_p_flp,
RE_MAGIC + RE_STRING + RE_AUTO + RE_STRICT);
if (regmatch.regprog != NULL)
{
regmatch.rm_ic = FALSE;
if (vim_regexec(&regmatch, line, 0))
{
if (wp->w_briopt_list > 0)
prev_list = wp->w_briopt_list;
else
prev_list = (*regmatch.endp - *regmatch.startp);
}
vim_regfree(regmatch.regprog);
}
}
}
bri = prev_indent + wp->w_briopt_shift;
@@ -958,22 +983,10 @@ get_breakindent_win(
// add additional indent for numbered lists
if (wp->w_briopt_list != 0)
{
regmatch_T regmatch;
regmatch.regprog = vim_regcomp(curbuf->b_p_flp,
RE_MAGIC + RE_STRING + RE_AUTO + RE_STRICT);
if (regmatch.regprog != NULL)
{
regmatch.rm_ic = FALSE;
if (vim_regexec(&regmatch, line, 0))
{
if (wp->w_briopt_list > 0)
bri += wp->w_briopt_list;
else
bri = (*regmatch.endp - *regmatch.startp);
}
vim_regfree(regmatch.regprog);
}
if (wp->w_briopt_list > 0)
bri += prev_list;
else
bri = prev_list;
}
// indent minus the length of the showbreak string