mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
fix(diff): handle long lines without crashing (#21389)
Fixes https://github.com/neovim/neovim/issues/21388
This commit is contained in:
@@ -85,7 +85,7 @@ static void update_path_flat(diffcmppath_T *diffcmppath, int score, size_t to, s
|
|||||||
diffcmppath[to].df_path_idx = path_idx + 1;
|
diffcmppath[to].df_path_idx = path_idx + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MATCH_CHAR_MAX_LEN 500
|
#define MATCH_CHAR_MAX_LEN 800
|
||||||
|
|
||||||
/// Return matching characters between "s1" and "s2" whilst respecting sequence order.
|
/// Return matching characters between "s1" and "s2" whilst respecting sequence order.
|
||||||
/// Consider the case of two strings 'AAACCC' and 'CCCAAA', the
|
/// Consider the case of two strings 'AAACCC' and 'CCCAAA', the
|
||||||
@@ -102,8 +102,8 @@ static void update_path_flat(diffcmppath_T *diffcmppath, int score, size_t to, s
|
|||||||
/// @param s2
|
/// @param s2
|
||||||
static int matching_chars(const char *s1, const char *s2)
|
static int matching_chars(const char *s1, const char *s2)
|
||||||
{
|
{
|
||||||
size_t s1len = MIN(MATCH_CHAR_MAX_LEN, line_len(s1));
|
size_t s1len = MIN(MATCH_CHAR_MAX_LEN - 1, line_len(s1));
|
||||||
size_t s2len = MIN(MATCH_CHAR_MAX_LEN, line_len(s2));
|
size_t s2len = MIN(MATCH_CHAR_MAX_LEN - 1, line_len(s2));
|
||||||
int matrix[2][MATCH_CHAR_MAX_LEN] = { 0 };
|
int matrix[2][MATCH_CHAR_MAX_LEN] = { 0 };
|
||||||
bool icur = 1; // save space by storing only two rows for i axis
|
bool icur = 1; // save space by storing only two rows for i axis
|
||||||
for (size_t i = 0; i < s1len; i++) {
|
for (size_t i = 0; i < s1len; i++) {
|
||||||
|
@@ -49,12 +49,11 @@ describe('Diff mode screen with 3 diffs open', function()
|
|||||||
[8] = {background = Screen.colors.Red1, bold = true};
|
[8] = {background = Screen.colors.Red1, bold = true};
|
||||||
[10] = {foreground = Screen.colors.Brown};
|
[10] = {foreground = Screen.colors.Brown};
|
||||||
[9] = {background = Screen.colors.Plum1};
|
[9] = {background = Screen.colors.Plum1};
|
||||||
})
|
})
|
||||||
feed('<c-w>=')
|
feed('<c-w>=')
|
||||||
feed(':windo set nu!<cr>')
|
feed(':windo set nu!<cr>')
|
||||||
|
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('setup the diff screen to look like a merge conflict with 3 files in diff mode', function()
|
describe('setup the diff screen to look like a merge conflict with 3 files in diff mode', function()
|
||||||
before_each(function()
|
before_each(function()
|
||||||
|
|
||||||
@@ -249,12 +248,11 @@ describe('Diff mode screen with 2 diffs open', function()
|
|||||||
[8] = {background = Screen.colors.Red1, bold = true};
|
[8] = {background = Screen.colors.Red1, bold = true};
|
||||||
[10] = {foreground = Screen.colors.Brown};
|
[10] = {foreground = Screen.colors.Brown};
|
||||||
[9] = {background = Screen.colors.Plum1};
|
[9] = {background = Screen.colors.Plum1};
|
||||||
})
|
})
|
||||||
feed('<c-w>=')
|
feed('<c-w>=')
|
||||||
feed(':windo set nu!<cr>')
|
feed(':windo set nu!<cr>')
|
||||||
|
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('setup a diff with 2 files and set linematch:30', function()
|
describe('setup a diff with 2 files and set linematch:30', function()
|
||||||
before_each(function()
|
before_each(function()
|
||||||
feed(':set diffopt+=linematch:30<cr>')
|
feed(':set diffopt+=linematch:30<cr>')
|
||||||
@@ -979,3 +977,19 @@ something
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe('regressions', function()
|
||||||
|
local screen
|
||||||
|
|
||||||
|
it("doesn't crash with long lines", function()
|
||||||
|
clear()
|
||||||
|
feed(':set diffopt+=linematch:30<cr>')
|
||||||
|
screen = Screen.new(100, 20)
|
||||||
|
screen:attach()
|
||||||
|
-- line must be greater than MATCH_CHAR_MAX_LEN
|
||||||
|
helpers.curbufmeths.set_lines(0, -1, false, { string.rep('a', 1000)..'hello' })
|
||||||
|
helpers.exec 'vnew'
|
||||||
|
helpers.curbufmeths.set_lines(0, -1, false, { string.rep('a', 1010)..'world' })
|
||||||
|
helpers.exec 'windo diffthis'
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
Reference in New Issue
Block a user