comparison src/move.c @ 2082:8ca3c9ad0bee v7.2.366

updated for version 7.2.366 Problem: CTRL-B doesn't go back to the first line of the buffer. Solution: Avoid an overflow when adding MAXCOL.
author Bram Moolenaar <bram@zimbu.org>
date Wed, 17 Feb 2010 18:20:37 +0100
parents 4483ee552619
children 7c8c7c95a865
comparison
equal deleted inserted replaced
2081:7b0e89b77216 2082:8ca3c9ad0bee
1608 1608
1609 /* 1609 /*
1610 * Add one line above "lp->lnum". This can be a filler line, a closed fold or 1610 * Add one line above "lp->lnum". This can be a filler line, a closed fold or
1611 * a (wrapped) text line. Uses and sets "lp->fill". 1611 * a (wrapped) text line. Uses and sets "lp->fill".
1612 * Returns the height of the added line in "lp->height". 1612 * Returns the height of the added line in "lp->height".
1613 * Lines above the first one are incredibly high. 1613 * Lines above the first one are incredibly high: MAXCOL.
1614 */ 1614 */
1615 static void 1615 static void
1616 topline_back(lp) 1616 topline_back(lp)
1617 lineoff_T *lp; 1617 lineoff_T *lp;
1618 { 1618 {
1940 curwin->w_topline > 1; 1940 curwin->w_topline > 1;
1941 curwin->w_topline = loff.lnum) 1941 curwin->w_topline = loff.lnum)
1942 { 1942 {
1943 loff.lnum = curwin->w_topline; 1943 loff.lnum = curwin->w_topline;
1944 topline_back(&loff); 1944 topline_back(&loff);
1945 if (used + loff.height > curwin->w_height) 1945 if (loff.height == MAXCOL || used + loff.height > curwin->w_height)
1946 break; 1946 break;
1947 used += loff.height; 1947 used += loff.height;
1948 #ifdef FEAT_DIFF 1948 #ifdef FEAT_DIFF
1949 curwin->w_topfill = loff.fill; 1949 curwin->w_topfill = loff.fill;
1950 #endif 1950 #endif
2019 ) 2019 )
2020 break; 2020 break;
2021 2021
2022 /* Add one line above */ 2022 /* Add one line above */
2023 topline_back(&loff); 2023 topline_back(&loff);
2024 used += loff.height; 2024 if (loff.height == MAXCOL)
2025 used = MAXCOL;
2026 else
2027 used += loff.height;
2025 if (used > curwin->w_height) 2028 if (used > curwin->w_height)
2026 break; 2029 break;
2027 if (loff.lnum >= curwin->w_botline 2030 if (loff.lnum >= curwin->w_botline
2028 #ifdef FEAT_DIFF 2031 #ifdef FEAT_DIFF
2029 && (loff.lnum > curwin->w_botline 2032 && (loff.lnum > curwin->w_botline
2173 } 2176 }
2174 2177
2175 if (below > above) /* add a line above the cursor */ 2178 if (below > above) /* add a line above the cursor */
2176 { 2179 {
2177 topline_back(&loff); 2180 topline_back(&loff);
2178 used += loff.height; 2181 if (loff.height == MAXCOL)
2182 used = MAXCOL;
2183 else
2184 used += loff.height;
2179 if (used > curwin->w_height) 2185 if (used > curwin->w_height)
2180 break; 2186 break;
2181 above += loff.height; 2187 above += loff.height;
2182 topline = loff.lnum; 2188 topline = loff.lnum;
2183 #ifdef FEAT_DIFF 2189 #ifdef FEAT_DIFF
2470 * at the bottom of the window. */ 2476 * at the bottom of the window. */
2471 n = 0; 2477 n = 0;
2472 while (n <= curwin->w_height && loff.lnum >= 1) 2478 while (n <= curwin->w_height && loff.lnum >= 1)
2473 { 2479 {
2474 topline_back(&loff); 2480 topline_back(&loff);
2475 n += loff.height; 2481 if (loff.height == MAXCOL)
2476 } 2482 n = MAXCOL;
2477 if (n <= curwin->w_height) /* at begin of file */ 2483 else
2484 n += loff.height;
2485 }
2486 if (loff.lnum < 1) /* at begin of file */
2478 { 2487 {
2479 curwin->w_topline = 1; 2488 curwin->w_topline = 1;
2480 #ifdef FEAT_DIFF 2489 #ifdef FEAT_DIFF
2481 max_topfill(); 2490 max_topfill();
2482 #endif 2491 #endif