From: Andrei Borzenkov Date: Wed, 30 Dec 2015 03:20:51 +0000 (+0300) Subject: menu: fix line count calculation for long lines X-Git-Tag: 2.02-beta3~148 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=93ecc3f1f8372e43101301866eea87aa9257a9e0;p=thirdparty%2Fgrub.git menu: fix line count calculation for long lines It gave one extra screen line if length was exactly equal to screen width. Reported by Michael Chang. Also-By: Michael Chang --- diff --git a/grub-core/normal/menu_entry.c b/grub-core/normal/menu_entry.c index 62c7e1627..2b732250d 100644 --- a/grub-core/normal/menu_entry.c +++ b/grub-core/normal/menu_entry.c @@ -126,9 +126,13 @@ ensure_space (struct line *linep, int extra) static int get_logical_num_lines (struct line *linep, struct per_term_screen *term_screen) { - return (grub_getstringwidth (linep->buf, linep->buf + linep->len, - term_screen->term) - / (unsigned) term_screen->geo.entry_width) + 1; + grub_size_t width = grub_getstringwidth (linep->buf, linep->buf + linep->len, + term_screen->term); + + /* Empty line still consumes space on screen */ + return width ? (width + (unsigned) term_screen->geo.entry_width - 1) / + (unsigned) term_screen->geo.entry_width + : 1; } static void