Skip to content

Commit

Permalink
patch 8.2.5164: invalid memory access after diff buffer manipulations
Browse files Browse the repository at this point in the history
Problem:    Invalid memory access after diff buffer manipulations.
Solution:   Use zero offset when change removes all lines in a diff block.
  • Loading branch information
brammool committed Jun 26, 2022
1 parent cd38bb4 commit c101abf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/diff.c
Expand Up @@ -403,9 +403,9 @@ diff_mark_adjust_tp(
// 2. 3. 4. 5.: inserted/deleted lines touching this diff.
if (deleted > 0)
{
off = 0;
if (dp->df_lnum[idx] >= line1)
{
off = dp->df_lnum[idx] - lnum_deleted;
if (last <= line2)
{
// 4. delete all lines of diff
Expand All @@ -426,6 +426,7 @@ diff_mark_adjust_tp(
else
{
// 5. delete lines at or just before top of diff
off = dp->df_lnum[idx] - lnum_deleted;
n = off;
dp->df_count[idx] -= line2 - dp->df_lnum[idx] + 1;
check_unchanged = TRUE;
Expand All @@ -434,7 +435,6 @@ diff_mark_adjust_tp(
}
else
{
off = 0;
if (last < line2)
{
// 2. delete at end of diff
Expand Down
12 changes: 12 additions & 0 deletions src/testdir/test_diffmode.vim
Expand Up @@ -1615,5 +1615,17 @@ func Test_diff_only()
%bwipe!
endfunc

" This was causing invalid diff block values
" FIXME: somehow this causes a valgrind error when run directly but not when
" run as a test.
func Test_diff_manipulations()
set diff
split 0
sil! norm RdoobdeuRdoobdeuRdoobdeu

set nodiff
%bwipe!
endfunc


" vim: shiftwidth=2 sts=2 expandtab
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -735,6 +735,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
5164,
/**/
5163,
/**/
Expand Down

0 comments on commit c101abf

Please sign in to comment.