To: vim_dev@googlegroups.com Subject: Patch 8.2.1220 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1220 Problem: memory access error when dragging a popup window over a buffer with folding. Solution: Avoid going over the end of the cache. (closes #6438) Files: src/mouse.c, src/testdir/test_popupwin.vim, src/testdir/dumps/Test_popupwin_term_01.dump, src/testdir/dumps/Test_popupwin_term_02.dump, src/testdir/dumps/Test_popupwin_term_03.dump, src/testdir/dumps/Test_popupwin_term_04.dump *** ../vim-8.2.1219/src/mouse.c 2020-07-12 13:47:38.808013098 +0200 --- src/mouse.c 2020-07-15 17:27:30.370950842 +0200 *************** *** 2839,2848 **** /* * Compute the buffer line position from the screen position "rowp" / "colp" in * window "win". ! * "plines_cache" can be NULL (no cache) or an array with "win->w_height" ! * entries that caches the plines_win() result from a previous call. Entry is ! * zero if not computed yet. There must be no text or setting changes since ! * the entry is put in the cache. * Returns TRUE if the position is below the last line. */ int --- 2839,2848 ---- /* * Compute the buffer line position from the screen position "rowp" / "colp" in * window "win". ! * "plines_cache" can be NULL (no cache) or an array with "Rows" entries that ! * caches the plines_win() result from a previous call. Entry is zero if not ! * computed yet. There must be no text or setting changes since the entry is ! * put in the cache. * Returns TRUE if the position is below the last line. */ int *************** *** 2871,2877 **** { int cache_idx = lnum - win->w_topline; ! if (plines_cache != NULL && plines_cache[cache_idx] > 0) count = plines_cache[cache_idx]; else { --- 2871,2880 ---- { int cache_idx = lnum - win->w_topline; ! // Only "Rows" lines are cached, with folding we'll run out of entries ! // and use the slow way. ! if (plines_cache != NULL && cache_idx < Rows ! && plines_cache[cache_idx] > 0) count = plines_cache[cache_idx]; else { *************** *** 2892,2898 **** else #endif count = plines_win(win, lnum, TRUE); ! if (plines_cache != NULL) plines_cache[cache_idx] = count; } if (count > row) --- 2895,2901 ---- else #endif count = plines_win(win, lnum, TRUE); ! if (plines_cache != NULL && cache_idx < Rows) plines_cache[cache_idx] = count; } if (count > row) *** ../vim-8.2.1219/src/testdir/test_popupwin.vim 2020-07-12 19:52:32.707024154 +0200 --- src/testdir/test_popupwin.vim 2020-07-15 17:30:23.750585271 +0200 *************** *** 584,592 **** " create a popup that covers the terminal window let lines =<< trim END set shell=/bin/sh noruler let $PS1 = 'vim> ' ! terminal $wincmd w let winid = popup_create(['1111', '2222'], #{ \ drag: 1, --- 584,599 ---- " create a popup that covers the terminal window let lines =<< trim END + set foldmethod=marker + call setline(1, range(100)) + for nr in range(7) + call setline(nr * 12 + 1, "fold {{{") + call setline(nr * 12 + 11 , "end }}}") + endfor + %foldclose set shell=/bin/sh noruler let $PS1 = 'vim> ' ! terminal ++rows=4 $wincmd w let winid = popup_create(['1111', '2222'], #{ \ drag: 1, *************** *** 594,612 **** \ border: [], \ line: 3, \ }) ! func Dragit() call feedkeys("\\\\\", "xt") endfunc map :call test_setmouse(3, &columns / 2) map :call test_setmouse(3, &columns / 2 - 20) END call writefile(lines, 'XtestPopupTerm') ! let buf = RunVimInTerminal('-S XtestPopupTerm', #{rows: 10}) call VerifyScreenDump(buf, 'Test_popupwin_term_01', {}) ! call term_sendkeys(buf, ":call Dragit()\") call VerifyScreenDump(buf, 'Test_popupwin_term_02', {}) " clean up call StopVimInTerminal(buf) call delete('XtestPopupTerm') --- 601,633 ---- \ border: [], \ line: 3, \ }) ! func DragitLeft() call feedkeys("\\\\\", "xt") endfunc + func DragitDown() + call feedkeys("\\\\\", "xt") + endfunc + func DragitDownLeft() + call feedkeys("\\\\\", "xt") + endfunc map :call test_setmouse(3, &columns / 2) map :call test_setmouse(3, &columns / 2 - 20) + map :call test_setmouse(12, &columns / 2) + map :call test_setmouse(12, &columns / 2 - 20) END call writefile(lines, 'XtestPopupTerm') ! let buf = RunVimInTerminal('-S XtestPopupTerm', #{rows: 16}) call VerifyScreenDump(buf, 'Test_popupwin_term_01', {}) ! call term_sendkeys(buf, ":call DragitLeft()\") call VerifyScreenDump(buf, 'Test_popupwin_term_02', {}) + call term_sendkeys(buf, ":call DragitDown()\") + call VerifyScreenDump(buf, 'Test_popupwin_term_03', {}) + + call term_sendkeys(buf, ":call DragitDownLeft()\") + call VerifyScreenDump(buf, 'Test_popupwin_term_04', {}) + " clean up call StopVimInTerminal(buf) call delete('XtestPopupTerm') *** ../vim-8.2.1219/src/testdir/dumps/Test_popupwin_term_01.dump 2020-07-12 19:52:32.707024154 +0200 --- src/testdir/dumps/Test_popupwin_term_01.dump 2020-07-15 16:49:40.487326865 +0200 *************** *** 3,10 **** @34|╔+0#0000001#ffd7ff255|═@3|╗| +0#0000000#ffffff0@34 @34|║+0#0000001#ffd7ff255|1@3|║| +0#0000000#ffffff0@34 |!+0#ffffff16#00e0003|/|b|i|n|/|s|h| |[|r|u|n@1|i|n|g|]| @15|║+0#0000001#ffd7ff255|2@3|║| +0#ffffff16#00e0003@34 ! > +0#0000000#ffffff0@33|╚+0#0000001#ffd7ff255|═@3|⇲| +0#0000000#ffffff0@34 ! |~+0#4040ff13&| @73 ! |~| @73 ! |[+3#0000000&|N|o| |N|a|m|e|]| @65 | +0&&@74 --- 3,16 ---- @34|╔+0#0000001#ffd7ff255|═@3|╗| +0#0000000#ffffff0@34 @34|║+0#0000001#ffd7ff255|1@3|║| +0#0000000#ffffff0@34 |!+0#ffffff16#00e0003|/|b|i|n|/|s|h| |[|r|u|n@1|i|n|g|]| @15|║+0#0000001#ffd7ff255|2@3|║| +0#ffffff16#00e0003@34 ! >++0#0000e05#a8a8a8255|-@1| |1@1| |l|i|n|e|s|:| |f|o|l|d| |-@14|╚+0#0000001#ffd7ff255|═@3|⇲|-+0#0000e05#a8a8a8255@34 ! |1+0#0000000#ffffff0@1| @72 ! |++0#0000e05#a8a8a8255|-@1| |1@1| |l|i|n|e|s|:| |f|o|l|d| |-@55 ! |2+0#0000000#ffffff0|3| @72 ! |++0#0000e05#a8a8a8255|-@1| |1@1| |l|i|n|e|s|:| |f|o|l|d| |-@55 ! |3+0#0000000#ffffff0|5| @72 ! |++0#0000e05#a8a8a8255|-@1| |1@1| |l|i|n|e|s|:| |f|o|l|d| |-@55 ! |4+0#0000000#ffffff0|7| @72 ! |++0#0000e05#a8a8a8255|-@1| |1@1| |l|i|n|e|s|:| |f|o|l|d| |-@55 ! |[+3#0000000#ffffff0|N|o| |N|a|m|e|]| |[|+|]| @61 | +0&&@74 *** ../vim-8.2.1219/src/testdir/dumps/Test_popupwin_term_02.dump 2020-07-12 19:52:32.707024154 +0200 --- src/testdir/dumps/Test_popupwin_term_02.dump 2020-07-15 16:49:41.539327207 +0200 *************** *** 3,10 **** @14|╔+0#0000001#ffd7ff255|═@3|╗| +0#0000000#ffffff0@54 @14|║+0#0000001#ffd7ff255|1@3|║| +0#0000000#ffffff0@54 |!+0#ffffff16#00e0003|/|b|i|n|/|s|h| |[|r|u|n@1|║+0#0000001#ffd7ff255|2@3|║| +0#ffffff16#00e0003@54 ! > +0#0000000#ffffff0@13|╚+0#0000001#ffd7ff255|═@3|⇲| +0#0000000#ffffff0@54 ! |~+0#4040ff13&| @73 ! |~| @73 ! |[+3#0000000&|N|o| |N|a|m|e|]| @65 ! |:+0&&|c|a|l@1| |D|r|a|g|i|t|(|)| @60 --- 3,16 ---- @14|╔+0#0000001#ffd7ff255|═@3|╗| +0#0000000#ffffff0@54 @14|║+0#0000001#ffd7ff255|1@3|║| +0#0000000#ffffff0@54 |!+0#ffffff16#00e0003|/|b|i|n|/|s|h| |[|r|u|n@1|║+0#0000001#ffd7ff255|2@3|║| +0#ffffff16#00e0003@54 ! >++0#0000e05#a8a8a8255|-@1| |1@1| |l|i|n|e|s|:| |╚+0#0000001#ffd7ff255|═@3|⇲|-+0#0000e05#a8a8a8255@54 ! |1+0#0000000#ffffff0@1| @72 ! |++0#0000e05#a8a8a8255|-@1| |1@1| |l|i|n|e|s|:| |f|o|l|d| |-@55 ! |2+0#0000000#ffffff0|3| @72 ! |++0#0000e05#a8a8a8255|-@1| |1@1| |l|i|n|e|s|:| |f|o|l|d| |-@55 ! |3+0#0000000#ffffff0|5| @72 ! |++0#0000e05#a8a8a8255|-@1| |1@1| |l|i|n|e|s|:| |f|o|l|d| |-@55 ! |4+0#0000000#ffffff0|7| @72 ! |++0#0000e05#a8a8a8255|-@1| |1@1| |l|i|n|e|s|:| |f|o|l|d| |-@55 ! |[+3#0000000#ffffff0|N|o| |N|a|m|e|]| |[|+|]| @61 ! |:+0&&|c|a|l@1| |D|r|a|g|i|t|L|e|f|t|(|)| @56 *** ../vim-8.2.1219/src/testdir/dumps/Test_popupwin_term_03.dump 2020-07-15 17:34:02.114090187 +0200 --- src/testdir/dumps/Test_popupwin_term_03.dump 2020-07-15 16:55:40.859132264 +0200 *************** *** 0 **** --- 1,16 ---- + |v+0&#ffffff0|i|m|>| @70 + @75 + @75 + @75 + |!+0#ffffff16#00e0003|/|b|i|n|/|s|h| |[|r|u|n@1|i|n|g|]| @56 + >++0#0000e05#a8a8a8255|-@1| |1@1| |l|i|n|e|s|:| |f|o|l|d| |-@55 + |1+0#0000000#ffffff0@1| @72 + |++0#0000e05#a8a8a8255|-@1| |1@1| |l|i|n|e|s|:| |f|o|l|d| |-@55 + |2+0#0000000#ffffff0|3| @72 + |++0#0000e05#a8a8a8255|-@1| |1@1| |l|i|n|e|s|:| |f|o|l|d| |-@55 + |3+0#0000000#ffffff0|5| @72 + |++0#0000e05#a8a8a8255|-@1| |1@1| |l|i|n|e|s|:| |f|o|l|d| |-@14|╔+0#0000001#ffd7ff255|═@3|╗|-+0#0000e05#a8a8a8255@34 + |4+0#0000000#ffffff0|7| @31|║+0#0000001#ffd7ff255|1@3|║| +0#0000000#ffffff0@34 + |++0#0000e05#a8a8a8255|-@1| |1@1| |l|i|n|e|s|:| |f|o|l|d| |-@14|║+0#0000001#ffd7ff255|2@3|║|-+0#0000e05#a8a8a8255@34 + |[+3#0000000#ffffff0|N|o| |N|a|m|e|]| |[|+|]| @20|╚+0#0000001#ffd7ff255|═@3|⇲| +3#0000000#ffffff0@34 + |:+0&&|c|a|l@1| |D|r|a|g|i|t|D|o|w|n|(|)| @56 *** ../vim-8.2.1219/src/testdir/dumps/Test_popupwin_term_04.dump 2020-07-15 17:34:02.118090175 +0200 --- src/testdir/dumps/Test_popupwin_term_04.dump 2020-07-15 16:55:41.915130969 +0200 *************** *** 0 **** --- 1,16 ---- + |v+0&#ffffff0|i|m|>| @70 + @75 + @75 + @75 + |!+0#ffffff16#00e0003|/|b|i|n|/|s|h| |[|r|u|n@1|i|n|g|]| @56 + >++0#0000e05#a8a8a8255|-@1| |1@1| |l|i|n|e|s|:| |f|o|l|d| |-@55 + |1+0#0000000#ffffff0@1| @72 + |++0#0000e05#a8a8a8255|-@1| |1@1| |l|i|n|e|s|:| |f|o|l|d| |-@55 + |2+0#0000000#ffffff0|3| @72 + |++0#0000e05#a8a8a8255|-@1| |1@1| |l|i|n|e|s|:| |f|o|l|d| |-@55 + |3+0#0000000#ffffff0|5| @72 + |++0#0000e05#a8a8a8255|-@1| |1@1| |l|i|n|e|s|:| |╔+0#0000001#ffd7ff255|═@3|╗|-+0#0000e05#a8a8a8255@54 + |4+0#0000000#ffffff0|7| @11|║+0#0000001#ffd7ff255|1@3|║| +0#0000000#ffffff0@54 + |++0#0000e05#a8a8a8255|-@1| |1@1| |l|i|n|e|s|:| |║+0#0000001#ffd7ff255|2@3|║|-+0#0000e05#a8a8a8255@54 + |[+3#0000000#ffffff0|N|o| |N|a|m|e|]| |[|+|]| |╚+0#0000001#ffd7ff255|═@3|⇲| +3#0000000#ffffff0@54 + |:+0&&|c|a|l@1| |D|r|a|g|i|t|D|o|w|n|L|e|f|t|(|)| @52 *** ../vim-8.2.1219/src/version.c 2020-07-15 15:30:02.461232750 +0200 --- src/version.c 2020-07-15 17:35:06.077939731 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 1220, /**/ -- "So this is it," said Arthur, "we are going to die." "Yes," said Ford, "except...no! Wait a minute!" He suddenly lunged across the chamber at something behind Arthur's line of vision. "What's this switch?" he cried. "What? Where?" cried Arthur, twisting around. "No, I was only fooling," said Ford, "we are going to die after all." -- Douglas Adams, "The Hitchhiker's Guide to the Galaxy" /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///