To: vim_dev@googlegroups.com Subject: Patch 8.2.5164 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.5164 Problem: Invalid memory access after diff buffer manipulations. Solution: Use zero offset when change removes all lines in a diff block. Files: src/diff.c, src/testdir/test_diffmode.vim *** ../vim-8.2.5163/src/diff.c 2022-06-26 14:04:04.096859187 +0100 --- src/diff.c 2022-06-26 16:52:28.113205371 +0100 *************** *** 403,411 **** // 2. 3. 4. 5.: inserted/deleted lines touching this diff. if (deleted > 0) { if (dp->df_lnum[idx] >= line1) { - off = dp->df_lnum[idx] - lnum_deleted; if (last <= line2) { // 4. delete all lines of diff --- 403,411 ---- // 2. 3. 4. 5.: inserted/deleted lines touching this diff. if (deleted > 0) { + off = 0; if (dp->df_lnum[idx] >= line1) { if (last <= line2) { // 4. delete all lines of diff *************** *** 426,431 **** --- 426,432 ---- 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; *************** *** 434,440 **** } else { - off = 0; if (last < line2) { // 2. delete at end of diff --- 435,440 ---- *** ../vim-8.2.5163/src/testdir/test_diffmode.vim 2022-06-26 14:04:04.096859187 +0100 --- src/testdir/test_diffmode.vim 2022-06-26 16:52:06.629198006 +0100 *************** *** 1615,1619 **** --- 1615,1631 ---- %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 R doobdeuR doobdeuR doobdeu + + set nodiff + %bwipe! + endfunc + " vim: shiftwidth=2 sts=2 expandtab *** ../vim-8.2.5163/src/version.c 2022-06-26 14:04:04.096859187 +0100 --- src/version.c 2022-06-26 16:44:24.560990947 +0100 *************** *** 737,738 **** --- 737,740 ---- { /* Add new patch number below this line */ + /**/ + 5164, /**/ -- hundred-and-one symptoms of being an internet addict: 7. You finally do take that vacation, but only after buying a USB modem and a laptop. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///