Mercurial > vim
comparison src/mouse.c @ 21339:608f674c6035 v8.2.1220
patch 8.2.1220: memory access error when dragging a popup window
Commit: https://github.com/vim/vim/commit/452143c6bf0dcf76ef415281b0e4fbc3edff4b6b
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Jul 15 17:38:21 2020 +0200
patch 8.2.1220: memory access error when dragging a popup window
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)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 15 Jul 2020 17:45:03 +0200 |
parents | 51ff7e5abdda |
children | 35921b7fc07a |
comparison
equal
deleted
inserted
replaced
21338:84baaef59d19 | 21339:608f674c6035 |
---|---|
2837 // Functions also used for popup windows. | 2837 // Functions also used for popup windows. |
2838 | 2838 |
2839 /* | 2839 /* |
2840 * Compute the buffer line position from the screen position "rowp" / "colp" in | 2840 * Compute the buffer line position from the screen position "rowp" / "colp" in |
2841 * window "win". | 2841 * window "win". |
2842 * "plines_cache" can be NULL (no cache) or an array with "win->w_height" | 2842 * "plines_cache" can be NULL (no cache) or an array with "Rows" entries that |
2843 * entries that caches the plines_win() result from a previous call. Entry is | 2843 * caches the plines_win() result from a previous call. Entry is zero if not |
2844 * zero if not computed yet. There must be no text or setting changes since | 2844 * computed yet. There must be no text or setting changes since the entry is |
2845 * the entry is put in the cache. | 2845 * put in the cache. |
2846 * Returns TRUE if the position is below the last line. | 2846 * Returns TRUE if the position is below the last line. |
2847 */ | 2847 */ |
2848 int | 2848 int |
2849 mouse_comp_pos( | 2849 mouse_comp_pos( |
2850 win_T *win, | 2850 win_T *win, |
2869 | 2869 |
2870 while (row > 0) | 2870 while (row > 0) |
2871 { | 2871 { |
2872 int cache_idx = lnum - win->w_topline; | 2872 int cache_idx = lnum - win->w_topline; |
2873 | 2873 |
2874 if (plines_cache != NULL && plines_cache[cache_idx] > 0) | 2874 // Only "Rows" lines are cached, with folding we'll run out of entries |
2875 // and use the slow way. | |
2876 if (plines_cache != NULL && cache_idx < Rows | |
2877 && plines_cache[cache_idx] > 0) | |
2875 count = plines_cache[cache_idx]; | 2878 count = plines_cache[cache_idx]; |
2876 else | 2879 else |
2877 { | 2880 { |
2878 #ifdef FEAT_DIFF | 2881 #ifdef FEAT_DIFF |
2879 // Don't include filler lines in "count" | 2882 // Don't include filler lines in "count" |
2890 count = plines_win_nofill(win, lnum, TRUE); | 2893 count = plines_win_nofill(win, lnum, TRUE); |
2891 } | 2894 } |
2892 else | 2895 else |
2893 #endif | 2896 #endif |
2894 count = plines_win(win, lnum, TRUE); | 2897 count = plines_win(win, lnum, TRUE); |
2895 if (plines_cache != NULL) | 2898 if (plines_cache != NULL && cache_idx < Rows) |
2896 plines_cache[cache_idx] = count; | 2899 plines_cache[cache_idx] = count; |
2897 } | 2900 } |
2898 if (count > row) | 2901 if (count > row) |
2899 break; // Position is in this buffer line. | 2902 break; // Position is in this buffer line. |
2900 #ifdef FEAT_FOLDING | 2903 #ifdef FEAT_FOLDING |