]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
menu: fix line count calculation for long lines
authorAndrei Borzenkov <arvidjaar@gmail.com>
Wed, 30 Dec 2015 03:20:51 +0000 (06:20 +0300)
committerAndrei Borzenkov <arvidjaar@gmail.com>
Wed, 30 Dec 2015 03:20:51 +0000 (06:20 +0300)
It gave one extra screen line if length was exactly equal to screen
width.

Reported by Michael Chang.
Also-By: Michael Chang <mchang@suse.com>
grub-core/normal/menu_entry.c

index 62c7e16274b78df4cd7bf009f069a0cff5871a38..2b732250d4febc0755e3166a8819610df5ebb787 100644 (file)
@@ -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