]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Remove potential division by 0 in gfxmenu.
authorVladimir Serbinenko <phcoder@gmail.com>
Wed, 21 Jan 2015 14:56:53 +0000 (15:56 +0100)
committerVladimir Serbinenko <phcoder@gmail.com>
Wed, 21 Jan 2015 16:42:15 +0000 (17:42 +0100)
ChangeLog
grub-core/gfxmenu/gui_circular_progress.c
grub-core/gfxmenu/gui_list.c
grub-core/gfxmenu/gui_progress_bar.c

index 3383d469ed6e93fb82ee7b7196a8db06e00f7093..2d57d83fa1213080bdaa6f5bd0b86e91323fb05a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2015-01-20  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       Remove potential division by 0 in gfxmenu.
+
 2015-01-20  Vladimir Serbinenko  <phcoder@gmail.com>
 
        * grub-core/normal/menu_text.c (grub_menu_init_page): Avoid
index 04f68b8d327b16093afe8431669f035104812460..354dd7b73eead5e91e3835a11d43bc3542c003b0 100644 (file)
@@ -138,51 +138,53 @@ circprog_paint (void *vself, const grub_video_rect_t *region)
                           (height - center_height) / 2, 0, 0,
                           center_width, center_height);
 
-  int radius = grub_min (height, width) / 2 - grub_max (tick_height, tick_width) / 2 - 1;
-  unsigned nticks;
-  unsigned tick_begin;
-  unsigned tick_end;
-  if (self->end <= self->start
-      || self->value <= self->start)
-    nticks = 0;
-  else
-    nticks = ((unsigned) (self->num_ticks
-                         * (self->value - self->start)))
-      / ((unsigned) (self->end - self->start));
-  /* Do ticks appear or disappear as the value approached the end?  */
-  if (self->ticks_disappear)
+  if (self->num_ticks)
     {
-      tick_begin = nticks;
-      tick_end = self->num_ticks;
-    }
-  else
-    {
-      tick_begin = 0;
-      tick_end = nticks;
-    }
-
-  unsigned i;
-  for (i = tick_begin; i < tick_end; i++)
-    {
-       int x;
-       int y;
-       int angle;
-
-       /* Calculate the location of the tick.  */
-       angle = self->start_angle
-        + i * GRUB_TRIG_ANGLE_MAX / self->num_ticks;
-       x = width / 2 + (grub_cos (angle) * radius / GRUB_TRIG_FRACTION_SCALE);
-       y = height / 2 + (grub_sin (angle) * radius / GRUB_TRIG_FRACTION_SCALE);
-
-       /* Adjust (x,y) so the tick is centered.  */
-       x -= tick_width / 2;
-       y -= tick_height / 2;
-
-       /* Draw the tick.  */
-       grub_video_blit_bitmap (self->tick_bitmap, GRUB_VIDEO_BLIT_BLEND,
-                               x, y, 0, 0, tick_width, tick_height);
+      int radius = grub_min (height, width) / 2 - grub_max (tick_height, tick_width) / 2 - 1;
+      unsigned nticks;
+      unsigned tick_begin;
+      unsigned tick_end;
+      if (self->end <= self->start
+         || self->value <= self->start)
+       nticks = 0;
+      else
+       nticks = ((unsigned) (self->num_ticks
+                             * (self->value - self->start)))
+         / ((unsigned) (self->end - self->start));
+      /* Do ticks appear or disappear as the value approached the end?  */
+      if (self->ticks_disappear)
+       {
+         tick_begin = nticks;
+         tick_end = self->num_ticks;
+       }
+      else
+       {
+         tick_begin = 0;
+         tick_end = nticks;
+       }
+
+      unsigned i;
+      for (i = tick_begin; i < tick_end; i++)
+       {
+         int x;
+         int y;
+         int angle;
+
+         /* Calculate the location of the tick.  */
+         angle = self->start_angle
+           + i * GRUB_TRIG_ANGLE_MAX / self->num_ticks;
+         x = width / 2 + (grub_cos (angle) * radius / GRUB_TRIG_FRACTION_SCALE);
+         y = height / 2 + (grub_sin (angle) * radius / GRUB_TRIG_FRACTION_SCALE);
+
+         /* Adjust (x,y) so the tick is centered.  */
+         x -= tick_width / 2;
+         y -= tick_height / 2;
+
+         /* Draw the tick.  */
+         grub_video_blit_bitmap (self->tick_bitmap, GRUB_VIDEO_BLIT_BLEND,
+                                 x, y, 0, 0, tick_width, tick_height);
+       }
     }
-
   grub_gui_restore_viewport (&vpsave);
 }
 
index 5d26811f9d2cbdf9cb59eda07e3a4a7ccc033ec8..01477cdf2b3199b449eb9f1c00035c5b74e9f5f0 100644 (file)
@@ -131,6 +131,9 @@ get_num_shown_items (list_impl_t self)
   int max_top_pad = grub_max (item_top_pad, sel_top_pad);
   int max_bottom_pad = grub_max (item_bottom_pad, sel_bottom_pad);
 
+  if (item_height + item_vspace <= 0)
+    return 1;
+
   return (self->bounds.height + item_vspace - 2 * boxpad
           - max_top_pad - max_bottom_pad
           - box_top_pad - box_bottom_pad) / (item_height + item_vspace);
index 3501b01724f1b819f8b672ea06ea0b007bc90643..b128f08668ed811d8f57027e5a8c29d44ff82e6c 100644 (file)
@@ -118,9 +118,15 @@ draw_filled_rect_bar (grub_gui_progress_bar_t self)
                         f.width + 2, f.height + 2);
 
   /* Bar background.  */
-  int barwidth = (f.width
-                  * (self->value - self->start)
-                  / (self->end - self->start));
+  unsigned barwidth;
+
+  if (self->end <= self->start
+      || self->value <= self->start)
+    barwidth = 0;
+  else
+    barwidth = (f.width
+               * (self->value - self->start)
+               / (self->end - self->start));
   grub_video_fill_rect (grub_video_map_rgba_color (self->bg_color),
                         f.x + barwidth, f.y,
                         f.width - barwidth, f.height);