mirror of
https://github.com/neovim/neovim
synced 2025-07-16 01:01:49 +00:00
vim-patch:9.1.1510: Search completion may use invalid memory
Problem: Search completion may use invalid memory (after 9.1.1490).
Solution: Don't get two line pointers at the same time (zeertzjq).
closes: vim/vim#17661
5e34eec6f8
This commit is contained in:
@ -3875,15 +3875,13 @@ static int copy_substring_from_pos(pos_T *start, pos_T *end, char **match, pos_T
|
|||||||
|| (start->lnum == end->lnum && start->col >= end->col)) {
|
|| (start->lnum == end->lnum && start->col >= end->col)) {
|
||||||
return FAIL; // invalid range
|
return FAIL; // invalid range
|
||||||
}
|
}
|
||||||
// Get line pointers
|
|
||||||
char *start_line = ml_get(start->lnum);
|
|
||||||
char *end_line = ml_get(end->lnum);
|
|
||||||
|
|
||||||
// Use a growable string (ga)
|
// Use a growable string (ga)
|
||||||
garray_T ga;
|
garray_T ga;
|
||||||
ga_init(&ga, 1, 128);
|
ga_init(&ga, 1, 128);
|
||||||
|
|
||||||
// Append start line from start->col to end
|
// Append start line from start->col to end
|
||||||
|
char *start_line = ml_get(start->lnum);
|
||||||
char *start_ptr = start_line + start->col;
|
char *start_ptr = start_line + start->col;
|
||||||
bool is_single_line = start->lnum == end->lnum;
|
bool is_single_line = start->lnum == end->lnum;
|
||||||
|
|
||||||
@ -3906,6 +3904,7 @@ static int copy_substring_from_pos(pos_T *start, pos_T *end, char **match, pos_T
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Append partial end line (up to word end)
|
// Append partial end line (up to word end)
|
||||||
|
char *end_line = ml_get(end->lnum);
|
||||||
char *word_end = find_word_end(end_line + end->col);
|
char *word_end = find_word_end(end_line + end->col);
|
||||||
segment_len = (int)(word_end - end_line);
|
segment_len = (int)(word_end - end_line);
|
||||||
ga_grow(&ga, segment_len);
|
ga_grow(&ga, segment_len);
|
||||||
|
@ -4503,6 +4503,7 @@ func Test_search_wildmenu_screendump()
|
|||||||
CheckScreendump
|
CheckScreendump
|
||||||
|
|
||||||
let lines =<< trim [SCRIPT]
|
let lines =<< trim [SCRIPT]
|
||||||
|
call test_override('alloc_lines', 1)
|
||||||
set wildmenu wildcharm=<f5>
|
set wildmenu wildcharm=<f5>
|
||||||
call setline(1, ['the', 'these', 'the', 'foobar', 'thethe', 'thethere'])
|
call setline(1, ['the', 'these', 'the', 'foobar', 'thethe', 'thethere'])
|
||||||
[SCRIPT]
|
[SCRIPT]
|
||||||
|
Reference in New Issue
Block a user