vim-patch:9.0.1995: Invalid memory access with empty 'foldexpr' (#25530)

Problem:  Invalid memory access when 'foldexpr' returns empty string.
Solution: Check for NUL.

closes: vim/vim#13293

a991ce9c08
This commit is contained in:
zeertzjq
2023-10-07 06:32:06 +08:00
committed by GitHub
parent 5db076c7cc
commit 1ac588543d
2 changed files with 10 additions and 1 deletions

View File

@@ -1299,7 +1299,7 @@ int eval_foldexpr(win_T *wp, int *cp)
// If the result is a string, check if there is a non-digit before // If the result is a string, check if there is a non-digit before
// the number. // the number.
char *s = tv.vval.v_string; char *s = tv.vval.v_string;
if (!ascii_isdigit(*s) && *s != '-') { if (*s != NUL && !ascii_isdigit(*s) && *s != '-') {
*cp = (uint8_t)(*s++); *cp = (uint8_t)(*s++);
} }
retval = atol(s); retval = atol(s);

View File

@@ -1569,4 +1569,13 @@ func Test_foldcolumn_linebreak_control_char()
bwipe! bwipe!
endfunc endfunc
" This used to cause invalid memory access
func Test_foldexpr_return_empty_string()
new
setlocal foldexpr='' foldmethod=expr
redraw
bwipe!
endfunc