aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-03-04 11:17:39 +0800
committerzeertzjq <zeertzjq@outlook.com>2023-03-04 13:53:09 +0800
commit98e8464319439a934946c67bbcb9c78e865a08c8 (patch)
tree7d714172ef0542be7cd83051f974bb73321b9588
parent0a897f89c52b92cb518dae1c92de22ca1d170d2a (diff)
downloadrneovim-98e8464319439a934946c67bbcb9c78e865a08c8.tar.gz
rneovim-98e8464319439a934946c67bbcb9c78e865a08c8.tar.bz2
rneovim-98e8464319439a934946c67bbcb9c78e865a08c8.zip
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. https://github.com/vim/vim/commit/c2a79b87fc31080ba24394c0b30bab45f1bea852 Test changes have been squashed into the previous commit. Co-authored-by: Bram Moolenaar <Bram@vim.org>
-rw-r--r--src/nvim/indent.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/nvim/indent.c b/src/nvim/indent.c
index ee9bc48460..c57d26dbe0 100644
--- a/src/nvim/indent.c
+++ b/src/nvim/indent.c
@@ -803,11 +803,12 @@ bool briopt_check(win_T *wp)
int get_breakindent_win(win_T *wp, char *line)
FUNC_ATTR_NONNULL_ALL
{
- static int prev_indent = 0; // Cached indent value.
- static long prev_ts = 0L; // Cached tabstop value.
- static const char *prev_line = NULL; // cached pointer to line.
- static varnumber_T prev_tick = 0; // Changedtick of cached value.
- static long *prev_vts = NULL; // Cached vartabs values.
+ static int prev_indent = 0; // cached indent value
+ static long prev_ts = 0L; // cached tabstop value
+ static int prev_fnum = 0; // cached buffer number
+ static char *prev_line = NULL; // cached copy of "line"
+ 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_listopt = 0; // cached w_p_briopt_list 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);
// used cached indent, unless
- // - line pointer changed
+ // - buffer changed
// - 'tabstop' changed
+ // - buffer was changed
// - 'briopt_list changed' changed or
// - '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_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_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_tick = buf_get_changedtick(wp->w_buffer);
prev_vts = wp->w_buffer->b_p_vts_array;