aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/indent.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-03-04 14:19:53 +0800
committerGitHub <noreply@github.com>2023-03-04 14:19:53 +0800
commitde14f2c928f913d4fb617d693024eec5cf2223ec (patch)
tree34e2b7c7324382eb0058e1dffa2d1baa1ab2ae0d /src/nvim/indent.c
parent446c353a507834a3cbe9007b06e7e0c2c46b5ac7 (diff)
parentb7d59649acf43c76cc72b25c04bcae926a40b4fe (diff)
downloadrneovim-de14f2c928f913d4fb617d693024eec5cf2223ec.tar.gz
rneovim-de14f2c928f913d4fb617d693024eec5cf2223ec.tar.bz2
rneovim-de14f2c928f913d4fb617d693024eec5cf2223ec.zip
Merge pull request #22506 from zeertzjq/vim-9.0.0013
vim-patch:9.0.{partial:0013,0016}: fix memory access errors
Diffstat (limited to 'src/nvim/indent.c')
-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;