aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/lua/xdiff.c
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2024-09-26 16:10:11 +0100
committerLewis Russell <lewis6991@gmail.com>2024-09-30 11:51:33 +0100
commitc65646c2474d22948c604168a68f6626a645d1d2 (patch)
treefcf8e49ae06878638e0dacc34e08d7892ccc8524 /src/nvim/lua/xdiff.c
parent20251be15a4ad3f6e7016450ca3338d52b2f0951 (diff)
downloadrneovim-c65646c2474d22948c604168a68f6626a645d1d2.tar.gz
rneovim-c65646c2474d22948c604168a68f6626a645d1d2.tar.bz2
rneovim-c65646c2474d22948c604168a68f6626a645d1d2.zip
fix(diff): use mmfile_t in linematch
Problem: Linematch used to use strchr to navigate a string, however strchr does not supoprt embedded NULs. Solution: Use `mmfile_t` instead of `char *` in linematch and introduce `strnchr()`. Also remove heap allocations from `matching_char_iwhite()` Fixes: #30505
Diffstat (limited to 'src/nvim/lua/xdiff.c')
-rw-r--r--src/nvim/lua/xdiff.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/nvim/lua/xdiff.c b/src/nvim/lua/xdiff.c
index 8d791a7e74..b9f96abf73 100644
--- a/src/nvim/lua/xdiff.c
+++ b/src/nvim/lua/xdiff.c
@@ -67,11 +67,11 @@ static void get_linematch_results(lua_State *lstate, mmfile_t *ma, mmfile_t *mb,
int count_a, int start_b, int count_b, bool iwhite)
{
// get the pointer to char of the start of the diff to pass it to linematch algorithm
- const char *diff_begin[2] = { ma->ptr, mb->ptr };
- int diff_length[2] = { count_a, count_b };
+ mmfile_t ma0 = fastforward_buf_to_lnum(*ma, (linenr_T)start_a + 1);
+ mmfile_t mb0 = fastforward_buf_to_lnum(*mb, (linenr_T)start_b + 1);
- fastforward_buf_to_lnum(&diff_begin[0], (linenr_T)start_a + 1);
- fastforward_buf_to_lnum(&diff_begin[1], (linenr_T)start_b + 1);
+ const mmfile_t *diff_begin[2] = { &ma0, &mb0 };
+ int diff_length[2] = { count_a, count_b };
int *decisions = NULL;
size_t decisions_length = linematch_nbuffers(diff_begin, diff_length, 2, &decisions, iwhite);