From: Ben Pfaff Date: Sat, 27 May 2023 23:17:22 +0000 (-0700) Subject: histogram: Fix a couple of bugs. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3c9dec8e237078429961acbf67697aa06a44d644;p=pspp histogram: Fix a couple of bugs. The bug report wasn't specific enough to know that this fixes the problem, which was an assertion failure for assert (*adjusted_min <= min); in hist_find_pretty_no_of_bins(). Thanks to Stefan Huber for reporting these bugs. --- diff --git a/src/math/chart-geometry.c b/src/math/chart-geometry.c index 7029ddd737..eaa2c0159d 100644 --- a/src/math/chart-geometry.c +++ b/src/math/chart-geometry.c @@ -57,7 +57,6 @@ chart_get_scale (double high, double low, double *lower, double *interval, int *n_ticks) { - int i; double fitness = DBL_MAX; double logrange; *n_ticks = 0; @@ -74,7 +73,7 @@ chart_get_scale (double high, double low, logrange = floor(log10(high-low)); /* Find the most pleasing interval */ - for (i = 1; i < 4; ++i) + for (int i = 0; i < sizeof standard_tick / sizeof *standard_tick; i++) { double cinterval = standard_tick[i] * pow(10.0,logrange-1); double clower = floor(low/cinterval) * cinterval; diff --git a/src/math/histogram.c b/src/math/histogram.c index 264b078535..f054f824b8 100644 --- a/src/math/histogram.c +++ b/src/math/histogram.c @@ -107,6 +107,10 @@ hist_find_pretty_no_of_bins(double bin_width_in, double min, double max, *adjusted_min = floor((min - lower)/binwidth)*binwidth + lower; } + /* This should not happen, but sometimes it does. */ + if (*adjusted_min > min) + *adjusted_min = min; + nbins = ceil((max-*adjusted_min)/binwidth); *adjusted_max = nbins*binwidth + *adjusted_min;