[libchamplain/libchamplain-0-4] Watch/Prevent division by 0



commit 4611a64760dbbe76900b4b373a1756c3e5a057c4
Author: Pierre-Luc Beaudoin <pierre-luc pierlux com>
Date:   Tue Jan 5 23:19:09 2010 -0500

    Watch/Prevent division by 0

 champlain/champlain-view.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)
---
diff --git a/champlain/champlain-view.c b/champlain/champlain-view.c
index 20b7904..2803184 100644
--- a/champlain/champlain-view.c
+++ b/champlain/champlain-view.c
@@ -1143,25 +1143,28 @@ update_scale (ChamplainView *view)
       base = pow (10, base);
 
       /* How many times can it be fitted in our max scale width */
+      g_assert (base > 0);
+      g_assert (m_per_pixel * scale_width / base > 0);
       scale_width /= m_per_pixel * scale_width / base;
+      g_assert (scale_width > 0);
       factor = floor (priv->max_scale_width / scale_width);
       base *= factor;
       scale_width *= factor;
 
       if (priv->scale_unit == CHAMPLAIN_UNIT_KM)
         {
-          if (base / 1000 >= 1)
+          if (base / 1000.0 >= 1)
             {
-              base /= 1000; /* base is now in km */
+              base /= 1000.0; /* base is now in km */
               is_small_unit = FALSE;
             }
           final_unit = TRUE; /* Don't need to recompute */
         }
       else if (priv->scale_unit == CHAMPLAIN_UNIT_MILES)
         {
-          if (is_small_unit && base / 5280 >= 1)
+          if (is_small_unit && base / 5280.0 >= 1)
             {
-              m_per_pixel /= 5280; /* m_per_pixel is now in miles */
+              m_per_pixel /= 5280.0; /* m_per_pixel is now in miles */
               is_small_unit = FALSE;
               /* we need to recompute the base because 1000 ft != 1 mile */
             }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]