vim-patch:9.0.0016: comparing line pointer for 'breakindent' is not reliable

Problem:    Comparing line pointer for 'breakindent' is not reliable.
Solution:   Make a copy of the line.

c2a79b87fc

Test changes have been squashed into the previous commit.

Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
zeertzjq
2023-03-04 11:17:39 +08:00
parent 0a897f89c5
commit 98e8464319

View File

@@ -803,11 +803,12 @@ bool briopt_check(win_T *wp)
int get_breakindent_win(win_T *wp, char *line) int get_breakindent_win(win_T *wp, char *line)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
static int prev_indent = 0; // Cached indent value. static int prev_indent = 0; // cached indent value
static long prev_ts = 0L; // Cached tabstop value. static long prev_ts = 0L; // cached tabstop value
static const char *prev_line = NULL; // cached pointer to line. static int prev_fnum = 0; // cached buffer number
static varnumber_T prev_tick = 0; // Changedtick of cached value. static char *prev_line = NULL; // cached copy of "line"
static long *prev_vts = NULL; // Cached vartabs values. static varnumber_T prev_tick = 0; // changedtick of cached value
static long *prev_vts = NULL; // cached vartabs values
static int prev_list = 0; // cached list value static int prev_list = 0; // cached list value
static int prev_listopt = 0; // cached w_p_briopt_list value static int prev_listopt = 0; // cached w_p_briopt_list value
static char *prev_flp = NULL; // cached formatlistpat value static char *prev_flp = NULL; // cached formatlistpat value
@@ -818,16 +819,24 @@ int get_breakindent_win(win_T *wp, char *line)
&& (vim_strchr(p_cpo, CPO_NUMCOL) == NULL) ? number_width(wp) + 1 : 0); && (vim_strchr(p_cpo, CPO_NUMCOL) == NULL) ? number_width(wp) + 1 : 0);
// used cached indent, unless // used cached indent, unless
// - line pointer changed // - buffer changed
// - 'tabstop' changed // - 'tabstop' changed
// - buffer was changed
// - 'briopt_list changed' changed or // - 'briopt_list changed' changed or
// - 'formatlistpattern' changed // - 'formatlistpattern' changed
if (prev_line != line || prev_ts != wp->w_buffer->b_p_ts // - line changed
// - 'vartabs' changed
if (prev_fnum != wp->w_buffer->b_fnum
|| prev_ts != wp->w_buffer->b_p_ts
|| prev_tick != buf_get_changedtick(wp->w_buffer) || prev_tick != buf_get_changedtick(wp->w_buffer)
|| prev_listopt != wp->w_briopt_list || prev_listopt != wp->w_briopt_list
|| (prev_flp == NULL || (strcmp(prev_flp, get_flp_value(wp->w_buffer)) != 0)) || prev_flp == NULL
|| strcmp(prev_flp, get_flp_value(wp->w_buffer)) != 0
|| prev_line == NULL || strcmp(prev_line, line) != 0
|| prev_vts != wp->w_buffer->b_p_vts_array) { || prev_vts != wp->w_buffer->b_p_vts_array) {
prev_line = line; prev_fnum = wp->w_buffer->b_fnum;
xfree(prev_line);
prev_line = xstrdup(line);
prev_ts = wp->w_buffer->b_p_ts; prev_ts = wp->w_buffer->b_p_ts;
prev_tick = buf_get_changedtick(wp->w_buffer); prev_tick = buf_get_changedtick(wp->w_buffer);
prev_vts = wp->w_buffer->b_p_vts_array; prev_vts = wp->w_buffer->b_p_vts_array;