mirror of
https://github.com/neovim/neovim.git
synced 2024-12-20 03:05:11 -07:00
vim-patch:9.0.1225: reading past the end of a line when formatting text (#21937)
Problem: Reading past the end of a line when formatting text.
Solution: Check for not going over the end of the line.
11977f9175
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
parent
0f52e2c849
commit
108452aaba
@ -530,6 +530,9 @@ static bool same_leader(linenr_T lnum, int leader1_len, char *leader1_flags, int
|
||||
return leader2_len == 0;
|
||||
}
|
||||
|
||||
char *lnum_line = NULL;
|
||||
int line_len = 0;
|
||||
|
||||
// If first leader has 'f' flag, the lines can be joined only if the
|
||||
// second line does not have a leader.
|
||||
// If first leader has 'e' flag, the lines can never be joined.
|
||||
@ -544,7 +547,11 @@ static bool same_leader(linenr_T lnum, int leader1_len, char *leader1_flags, int
|
||||
return false;
|
||||
}
|
||||
if (*p == COM_START) {
|
||||
if (*(ml_get(lnum) + leader1_len) == NUL) {
|
||||
if (lnum_line == NULL) {
|
||||
lnum_line = ml_get(lnum);
|
||||
line_len = (int)strlen(lnum_line);
|
||||
}
|
||||
if (line_len <= leader1_len) {
|
||||
return false;
|
||||
}
|
||||
if (leader2_flags == NULL || leader2_len == 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user