Skip to content

Commit c101abf

Browse files
committed
patch 8.2.5164: invalid memory access after diff buffer manipulations
Problem: Invalid memory access after diff buffer manipulations. Solution: Use zero offset when change removes all lines in a diff block.
1 parent cd38bb4 commit c101abf

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

src/diff.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,9 @@ diff_mark_adjust_tp(
403403
// 2. 3. 4. 5.: inserted/deleted lines touching this diff.
404404
if (deleted > 0)
405405
{
406+
off = 0;
406407
if (dp->df_lnum[idx] >= line1)
407408
{
408-
off = dp->df_lnum[idx] - lnum_deleted;
409409
if (last <= line2)
410410
{
411411
// 4. delete all lines of diff
@@ -426,6 +426,7 @@ diff_mark_adjust_tp(
426426
else
427427
{
428428
// 5. delete lines at or just before top of diff
429+
off = dp->df_lnum[idx] - lnum_deleted;
429430
n = off;
430431
dp->df_count[idx] -= line2 - dp->df_lnum[idx] + 1;
431432
check_unchanged = TRUE;
@@ -434,7 +435,6 @@ diff_mark_adjust_tp(
434435
}
435436
else
436437
{
437-
off = 0;
438438
if (last < line2)
439439
{
440440
// 2. delete at end of diff

src/testdir/test_diffmode.vim

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,5 +1615,17 @@ func Test_diff_only()
16151615
%bwipe!
16161616
endfunc
16171617

1618+
" This was causing invalid diff block values
1619+
" FIXME: somehow this causes a valgrind error when run directly but not when
1620+
" run as a test.
1621+
func Test_diff_manipulations()
1622+
set diff
1623+
split 0
1624+
sil! norm RdoobdeuRdoobdeuRdoobdeu
1625+
1626+
set nodiff
1627+
%bwipe!
1628+
endfunc
1629+
16181630

16191631
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,8 @@ static char *(features[]) =
735735

736736
static int included_patches[] =
737737
{ /* Add new patch number below this line */
738+
/**/
739+
5164,
738740
/**/
739741
5163,
740742
/**/

0 commit comments

Comments
 (0)