From 8839366f43bf51b0c9c0dfbd171f7d09ec6a4bf9 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 10 Feb 2010 20:07:08 -0800 Subject: [PATCH] FREQUENCIES: Fix corner case for histogram calculation. calc_stats() assumes that ft->n_valid is nonzero. It has two callers, but only one of them was checking ft->valid. The other one (which produces a histogram) is fixed up by this commit. Found by Clang (http://clang-analyzer.llvm.org). --- src/language/stats/frequencies.q | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/language/stats/frequencies.q b/src/language/stats/frequencies.q index e52aaf0f..d00c90c9 100644 --- a/src/language/stats/frequencies.q +++ b/src/language/stats/frequencies.q @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2007, 2009 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2007, 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -601,7 +601,7 @@ postcalc (const struct dataset *ds) - if ( chart == GFT_HIST && var_is_numeric (v) ) + if ( chart == GFT_HIST && var_is_numeric (v) && ft->n_valid > 0) { double d[frq_n_stats]; struct histogram *hist ; @@ -1170,6 +1170,8 @@ calc_stats (const struct variable *v, double d[frq_n_stats]) /* Calculate percentiles. */ + assert (ft->n_valid > 0); + for (i = 0; i < n_percentiles; i++) { percentiles[i].flag = 0; -- 2.30.2