Set categoricals to NULL in one-pass covariance; avoid freeing NULL in categoricals_d...
[pspp-builds.git] / src / math / covariance.c
index c247148ee9f88d64a29edf36e087d79ab21e95cd..1b5a238558ac773fa30b7016bc83bf521b406e1c 100644 (file)
@@ -157,6 +157,7 @@ covariance_1pass_create (size_t n_vars, const struct variable **vars,
   cov->n_cm = (n_vars * (n_vars - 1)  ) / 2;
 
   cov->cm = xcalloc (sizeof *cov->cm, cov->n_cm);
+  cov->categoricals = NULL;
 
   return cov;
 }
@@ -338,7 +339,9 @@ covariance_accumulate_pass2 (struct covariance *cov, const struct ccase *c)
       assert (cov->state == 1);
       cov->state = 2;
 
-      cov->dim = cov->n_vars + categoricals_total (cov->categoricals);
+      cov->dim = cov->n_vars +
+       categoricals_total (cov->categoricals) - categoricals_get_n_variables (cov->categoricals);
+
       cov->n_cm = (cov->dim * (cov->dim - 1)  ) / 2;
       cov->cm = xcalloc (sizeof *cov->cm, cov->n_cm);