This is cleaner, prevent the percent from being greater than 100.

This commit is contained in:
Brian Callahan
2014-05-29 15:06:16 -04:00
parent 87489937bf
commit dbe51ae294

View File

@@ -623,6 +623,7 @@ void modeline(WINDOW *wp)
int lchar; /* character to draw line in buffer with */
int n; /* cursor position count */
int len; /* line/column display check */
int perc; /* percent down */
char sl[25]; /* line/column display (probably overkill) */
n = wp->w_toprow + wp->w_ntrows; /* Location */
@@ -675,8 +676,11 @@ void modeline(WINDOW *wp)
n += 3;
}
len = snprintf(sl, sizeof(sl), " %ld%% (%d,%d) ",
(long)((100*(wp->w_dotline + 1)) / curwp->w_bufp->b_lines),
perc = (100*(wp->w_dotline + 1)) / curwp->w_bufp->b_lines;
if (perc > 100)
perc = 100;
len = snprintf(sl, sizeof(sl), " %d%% (%d,%d) ", perc,
(wp->w_dotline + 1), getccol(FALSE));
if (len < sizeof(sl) && len != -1)
n += vtputs(sl);