[clutter-interval] Fix calculation of interval for unsigned types
authorNeil Roberts <neil@linux.intel.com>
Wed, 17 Dec 2008 19:26:24 +0000 (19:26 +0000)
committerNeil Roberts <neil@linux.intel.com>
Wed, 17 Dec 2008 19:26:24 +0000 (19:26 +0000)
The patch makes it cast to double before subtracting the original
value from the target value. Otherwise if the target value is less
than the original value then the subtraction will overflow and the
factor will be multiplied by a very large number instead of the
desired interval.

The problem is demonstrable using the border-width property of
ClutterRectangle.

clutter/clutter-interval.c

index f8d6c4a..5f2924d 100644 (file)
@@ -206,7 +206,7 @@ clutter_interval_real_compute_value (ClutterInterval *interval,
         ia = g_value_get_uint (initial);
         ib = g_value_get_uint (final);
 
-        res = (factor * (ib - ia)) + ia;
+        res = (factor * (ib - (gdouble) ia)) + ia;
 
         g_value_set_uint (value, res);
       }
@@ -219,7 +219,7 @@ clutter_interval_real_compute_value (ClutterInterval *interval,
         ia = g_value_get_uchar (initial);
         ib = g_value_get_uchar (final);
 
-        res = (factor * (ib - ia)) + ia;
+        res = (factor * (ib - (gdouble) ia)) + ia;
 
         g_value_set_uchar (value, res);
       }