FACTOR: prevent crash if the dataset is empty.
[pspp-builds.git] / src / math / covariance.c
index 61f54f50752704e7e9717378574930f3a01b4752..b5a4166dfa40643c5a71c88f37ceb7b4c604b1d5 100644 (file)
@@ -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)
     {