Skip to contentSkip to conversation

normal: fix get_logical_num_lines

PATCH In review Michael Chang 3 participants 7 messages Dec 23, 2015 – Dec 29, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 normal: fix get_logical_num_lines

In menu editing mode, grub2 shows bogus line if the character being edited is at last column of entry. This patch fixes the problem by having the get_logical_num_lines function to calculate correct number of lines.

---
 grub-core/normal/menu_entry.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/normal/menu_entry.c +1 -1
index 62c7e16..1d4b0c6 100644
@@ -128,7 +128,7 @@ 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;
+	  / ((unsigned) term_screen->geo.entry_width + 1)) + 1;
 }
 
 static void
Signature · 1 line
2.6.3
#1 lore raw
Quoted 5 lines · Michael Chang

In menu editing mode, grub2 shows bogus line if the character being edited is at last column of entry. This patch fixes the problem by having the get_logical_num_lines function to calculate correct number of lines.

There is one more occurrence in update_screen (); could you check if this needs fix too?

grub_size_t t = grub_getstringwidth (linep->buf, linep->buf + screen->column,

      term_screen->term);

y += t / (unsigned) term_screen->geo.entry_width;

Quoted 25 lines
---
 grub-core/normal/menu_entry.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/normal/menu_entry.c +1 -2
index 62c7e16..1d4b0c6 100644
@@ -128,7 +128,7 @@ 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;
+         / ((unsigned) term_screen->geo.entry_width + 1)) + 1;
 }
 
 static void
--

2.6.3

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#2 lore raw
Quoted 7 lines · Andrei Borzenkov
Quoted 5 lines · Michael Chang

In menu editing mode, grub2 shows bogus line if the character being edited is at last column of entry. This patch fixes the problem by having the get_logical_num_lines function to calculate correct number of lines.

Quoted 6 lines

There is one more occurrence in update_screen (); could you check if this needs fix too?

grub_size_t t = grub_getstringwidth (linep->buf, linep->buf + screen->column,

      term_screen->term);

y += t / (unsigned) term_screen->geo.entry_width;

No, as the check followed has bailed it out.

if (t % (unsigned) term_screen->geo.entry_width == 0

        && t != 0 &&  screen->column == linep->len)
	    y--;

Of course, we can try to make the code more terse by the same fix so that we can remove the check. Should I submit a new patch for that ?

Thanks,
Michael

#3 lore raw
In reply to Michael Chang
Quoted 14 lines · Michael Chang

In menu editing mode, grub2 shows bogus line if the character being edited is at last column of entry. This patch fixes the problem by having the get_logical_num_lines function to calculate correct number of lines.

---
 grub-core/normal/menu_entry.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/normal/menu_entry.c +0 -0
index 62c7e16..1d4b0c6 100644

grub-core/normal/menu_entry.c get_logical_num_lines (struct line *linep, struct per_term_screen *term_screen) · line 131

Quoted 5 lines
grub-core/normal/menu_entry.c +1 -1
@@ -128,7 +128,7 @@ 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;
+         / ((unsigned) term_screen->geo.entry_width + 1)) + 1;

No, that's wrong. Consider entry_width = 10 and grub_getstringwidth =
21. It needs 3 lines but your change gives only 2.

It sounds like we need

string_width = grub_getstringwidth (linep->buf, linep->buf + linep->len, term_screen->term);
if (!string_width)
return 1;
return (string_width + (unsigned) term_screen->geo.entry_width - 1) / (unsigned) term_screen->geo.entry_width;

Could you test if it works for you?

#4 lore raw
Quoted 10 lines · Andrei Borzenkov
Quoted 9 lines · Michael Chang

In menu editing mode, grub2 shows bogus line if the character being edited is at last column of entry. This patch fixes the problem by having the get_logical_num_lines function to calculate correct number of lines.

---
 grub-core/normal/menu_entry.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

grub-core/normal/menu_entry.c get_logical_num_lines (struct line *linep, struct per_term_screen *term_screen) · line 131

Quoted 10 lines
grub-core/normal/menu_entry.c +1 -1
index 62c7e16..1d4b0c6 100644
@@ -128,7 +128,7 @@ 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;
+         / ((unsigned) term_screen->geo.entry_width + 1)) + 1;

No, that's wrong. Consider entry_width = 10 and grub_getstringwidth =
21. It needs 3 lines but your change gives only 2.

Alas! Indeed I am mistaken here. We should minus the numerator by one but not adding one to denominator. Thanks for your check. :)

Quoted 11 lines

It sounds like we need

string_width = grub_getstringwidth (linep->buf, linep->buf + linep->len, term_screen->term);
if (!string_width)
return 1;
return (string_width + (unsigned) term_screen->geo.entry_width - 1) / (unsigned) term_screen->geo.entry_width;

Could you test if it works for you?

Yes. It works great.

Thanks,
Michael

#5 lore raw
Quoted 10 lines · Michael Chang
Quoted 9 lines · Andrei Borzenkov

It sounds like we need

string_width = grub_getstringwidth (linep->buf, linep->buf + linep->len, term_screen->term);
if (!string_width)
return 1;
return (string_width + (unsigned) term_screen->geo.entry_width - 1) / (unsigned) term_screen->geo.entry_width;

Quoted 3 lines
Quoted 1 line

Could you test if it works for you?

Yes. It works great.

Hi Andrei,

I found we had a down stream bug opened for the problem a while ago that could be fixed by the patch.

https://bugzilla.suse.com/show_bug.cgi?id=943585

So please consider to commit your patch if you think it's ready to go as well after the testing.

Thanks,
Michael

#6 lore raw
In reply to Michael Chang
Quoted 38 lines · Michael Chang
Quoted 10 lines · Andrei Borzenkov
Quoted 9 lines · Michael Chang

In menu editing mode, grub2 shows bogus line if the character being edited is at last column of entry. This patch fixes the problem by having the get_logical_num_lines function to calculate correct number of lines.

---
 grub-core/normal/menu_entry.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

grub-core/normal/menu_entry.c get_logical_num_lines (struct line *linep, struct per_term_screen *term_screen) · line 131

Quoted 10 lines
grub-core/normal/menu_entry.c +1 -1
index 62c7e16..1d4b0c6 100644
@@ -128,7 +128,7 @@ 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;
+         / ((unsigned) term_screen->geo.entry_width + 1)) + 1;

No, that's wrong. Consider entry_width = 10 and grub_getstringwidth =
21. It needs 3 lines but your change gives only 2.

Alas! Indeed I am mistaken here. We should minus the numerator by one but not adding one to denominator. Thanks for your check. :)

Quoted 10 lines

It sounds like we need

string_width = grub_getstringwidth (linep->buf, linep->buf + linep->len, term_screen->term);
if (!string_width)
return 1;
return (string_width + (unsigned) term_screen->geo.entry_width - 1) / (unsigned) term_screen->geo.entry_width;

Quoted 3 lines
Quoted 1 line

Could you test if it works for you?

Yes. It works great.

@Anrei: please go ahead.

Quoted 9 lines

Thanks,
Michael

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel