Subject: | [PATCH] Infinite loop in GD::Graph::axestype::_best_ends |
Distribution: GDGraph 1.43
File: axestype.pm (revision 1.44)
Description:
When the min and max values for the y-axis are both negative, halving the minimum and increasing the maximum by 50% results in a minimum greater than the maximum, giving a negative range. This leads to an infinite loop in the sub _best_ends at the following line:
1651 while ($s > $range) { $s /= 10 }
as $s is never going to become negative, just closer and closer to zero. The patch below resolves this issue.
--- axestype.pm.orig 2003-12-09 17:06:53.000000000 +1100
+++ axestype.pm 2004-02-11 15:42:07.000000000 +1100
@@ -1622,15 +1622,15 @@
my ($best_min, $best_max, $best_num) = ($min, $max, 1);
+ # Check that min and max are not the same, and not 0
+ ($min, $max) = ($min != 0) ? ($min * 0.5, $min * 1.5) : (-1,1)
+ if ($max == $min);
+
# mgjv - Sometimes, for odd values, and only one data set, this will be
# necessary _after_ the previous step, not before. Data sets of one
# long with negative values were causing infinite loops later on.
($min, $max) = ($max, $min) if ($min > $max);
- # Check that min and max are not the same, and not 0
- ($min, $max) = ($min != 0) ? ($min * 0.5, $min * 1.5) : (-1,1)
- if ($max == $min);
-
my @n = ref($n_ref) ? @$n_ref : $n_ref;
if (@n <= 0)