]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
* grub-core/gfxmenu/gui_circular_progress.c (circprog_paint): Avoid
authorVladimir Serbinenko <phcoder@gmail.com>
Fri, 8 Nov 2013 14:43:07 +0000 (15:43 +0100)
committerVladimir Serbinenko <phcoder@gmail.com>
Fri, 8 Nov 2013 14:43:07 +0000 (15:43 +0100)
division by-zero and senseless negative divisions.
(circprog_set_property): Don't accept negative num_ticks.

ChangeLog
grub-core/gfxmenu/gui_circular_progress.c

index f55a01d57257a94e01c1428fa01792236db9cab3..def001a5bf739f7410af9b3fd082c04c0492d0c0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2013-11-08  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       * grub-core/gfxmenu/gui_circular_progress.c (circprog_paint): Avoid
+       division by-zero and senseless negative divisions.
+       (circprog_set_property): Don't accept negative num_ticks.
+
 2013-11-08  Vladimir Serbinenko  <phcoder@gmail.com>
 
        * grub-core/gfxmenu/gui_progress_bar.c (draw_pixmap_bar): Avoid
index 284a75a5e2547b838df6e7fd37be4a983aef1235..249019ef06470efedfd68f2e3031edb5f8fc6fc3 100644 (file)
@@ -37,7 +37,7 @@ struct grub_gui_circular_progress
   int start;
   int end;
   int value;
-  int num_ticks;
+  unsigned num_ticks;
   int start_angle;
   int ticks_disappear;
   char *theme_dir;
@@ -139,15 +139,16 @@ circprog_paint (void *vself, const grub_video_rect_t *region)
                           center_width, center_height);
 
   int radius = grub_min (height, width) / 2 - grub_max (tick_height, tick_width) / 2 - 1;
-  int nticks;
-  int tick_begin;
-  int tick_end;
-  if (self->end == self->start)
+  unsigned nticks;
+  unsigned tick_begin;
+  unsigned tick_end;
+  if (self->end <= self->start
+      || self->value <= self->start)
     nticks = 0;
   else
-    nticks = (self->num_ticks
-             * (self->value - self->start)
-             / (self->end - self->start));
+    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)
     {
@@ -160,7 +161,7 @@ circprog_paint (void *vself, const grub_video_rect_t *region)
       tick_end = nticks;
     }
 
-  int i;
+  unsigned i;
   for (i = tick_begin; i < tick_end; i++)
     {
        int x;
@@ -168,7 +169,8 @@ circprog_paint (void *vself, const grub_video_rect_t *region)
        int angle;
 
        /* Calculate the location of the tick.  */
-       angle = self->start_angle + i * GRUB_TRIG_ANGLE_MAX / self->num_ticks;
+       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);
 
@@ -248,7 +250,7 @@ circprog_set_property (void *vself, const char *name, const char *value)
   circular_progress_t self = vself;
   if (grub_strcmp (name, "num_ticks") == 0)
     {
-      self->num_ticks = grub_strtol (value, 0, 10);
+      self->num_ticks = grub_strtoul (value, 0, 10);
     }
   else if (grub_strcmp (name, "start_angle") == 0)
     {