From: John Darrington Date: Sat, 31 Jul 2010 09:55:18 +0000 (+0200) Subject: FACTOR: prevent crash if the dataset is empty. X-Git-Tag: v0.7.6~312 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b5831d68df1824881f9117bf2297957a6e49f64;p=pspp-builds.git FACTOR: prevent crash if the dataset is empty. The FACTOR command crashed if there were no cases which had non-missing values for all variables. This change emits a warning in this case and does no analysis. --- diff --git a/src/language/stats/factor.c b/src/language/stats/factor.c index a2a8e5df..d50d6ad3 100644 --- a/src/language/stats/factor.c +++ b/src/language/stats/factor.c @@ -1694,6 +1694,12 @@ do_factor (const struct cmd_factor *factor, struct casereader *r) idata->cov = covariance_calculate (cov); + if (idata->cov == NULL) + { + msg (MW, _("The dataset contains no complete observations. No analysis will be performed.")); + goto finish; + } + var_matrix = covariance_moments (cov, MOMENT_VARIANCE); mean_matrix = covariance_moments (cov, MOMENT_MEAN); idata->n = covariance_moments (cov, MOMENT_NONE); diff --git a/src/math/covariance.c b/src/math/covariance.c index 61f54f50..b5a4166d 100644 --- a/src/math/covariance.c +++ b/src/math/covariance.c @@ -601,7 +601,8 @@ covariance_calculate_single_pass (struct covariance *cov) const gsl_matrix * covariance_calculate (struct covariance *cov) { - assert ( cov->state > 0 ); + if ( cov->state <= 0 ) + return NULL; switch (cov->passes) { @@ -681,7 +682,8 @@ covariance_calculate_single_pass_unnormalized (struct covariance *cov) const gsl_matrix * covariance_calculate_unnormalized (struct covariance *cov) { - assert ( cov->state > 0 ); + if ( cov->state <= 0 ) + return NULL; switch (cov->passes) { diff --git a/tests/language/stats/factor.at b/tests/language/stats/factor.at index f1d4b236..ca01ca80 100644 --- a/tests/language/stats/factor.at +++ b/tests/language/stats/factor.at @@ -1775,4 +1775,24 @@ science,.900,.198 socst,.222,.922 ]) -AT_CLEANUP \ No newline at end of file +AT_CLEANUP + + + +AT_SETUP([FACTOR empty dataset]) +dnl Test that something sane happens when the dataset contains no complete observations + +AT_DATA([factor-empty.sps], + [data list notable list /x * y * z *. +begin data. +3.4 . 92.9 +. 32.09 34.2 +1.00 19.80 . +2.00 . 3.6 +end data. + +factor /variables = ALL. +]) + +AT_CHECK([pspp -O format=csv factor-empty.sps], [0], [ignore]) +AT_CLEANUP