Replace some calls to xcalloc with XCALLOC
authorJohn Darrington <john@darrington.wattle.id.au>
Sat, 27 Jun 2020 05:27:25 +0000 (07:27 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 27 Jun 2020 05:27:25 +0000 (07:27 +0200)
24 files changed:
src/data/mdd-writer.c
src/language/data-io/matrix-data.c
src/language/data-io/matrix-reader.c
src/language/stats/friedman.c
src/language/stats/glm.c
src/language/stats/kruskal-wallis.c
src/language/stats/ks-one-sample.c
src/language/stats/mann-whitney.c
src/language/stats/mcnemar.c
src/language/stats/means.c
src/language/stats/median.c
src/language/stats/roc.c
src/language/stats/runs.c
src/language/stats/sign.c
src/language/stats/t-test-indep.c
src/language/stats/wilcoxon.c
src/libpspp/model-checker.c
src/math/categoricals.c
src/output/pivot-output.c
src/output/pivot-table.c
src/output/spv/spv-legacy-data.c
src/output/spv/spv-legacy-decoder.c
src/output/spv/spv-light-decoder.c
src/ui/gui/psppire-import-assistant.c

index 3db5f2bd3f22eb3168e4f6e1d7af7b570f7ed01c..5e5eaa743dc0b639715329ee00d3c76185b38eed 100644 (file)
@@ -148,8 +148,8 @@ all_variables (struct dictionary *dict)
   size_t var_count = n_sets + string_set_count (&var_names);
 
   /* Allocate an array of var_or_mrset pointers (initially null). */
-  struct var_or_mrset *var_or_mrset_array = xcalloc (
-    var_count, sizeof *var_or_mrset_array);
+  struct var_or_mrset *var_or_mrset_array
+    = XCALLOC (var_count, struct var_or_mrset);
 
   /* Fill the array. */
   struct string_set added_mrsets = STRING_SET_INITIALIZER (added_mrsets);
index 8ce325154bdf9d959a8390a23e5569413086cf72..50a34642be79cebb749cc07ff0cc7932618d3f50 100644 (file)
@@ -137,7 +137,7 @@ preprocess (struct casereader *casereader0, const struct dictionary *dict, void
   /* Make an initial pass to populate our temporary matrix */
   struct casereader *pass0 = casereader_clone (casereader0);
   struct ccase *c;
-  union value *prev_values = xcalloc (mformat->n_split_vars, sizeof *prev_values);
+  union value *prev_values = XCALLOC (mformat->n_split_vars,  union value);
   int row = (mformat->triangle == LOWER && mformat->diagonal == NO_DIAGONAL) ? 1 : 0;
   bool first_case = true;
   for (; (c = casereader_read (pass0)) != NULL; case_unref (c))
index 6e73962a6acf1f19fd57c8bb040f3a3c815f9cab..f1dbae184facb82ecd97826cdf465b03d0a252a7 100644 (file)
@@ -213,7 +213,7 @@ next_matrix_from_reader (struct matrix_material *mm,
   mm->mean_matrix = mr->mean_vectors;
   mm->var_matrix = mr->var_vectors;
 
-  struct substring *var_names = xcalloc (n_vars, sizeof *var_names);
+  struct substring *var_names = XCALLOC (n_vars,  struct substring);
   for (int i = 0; i < n_vars; ++i)
     {
       ss_alloc_substring (var_names + i, ss_cstr (var_get_name (vars[i])));
index e2b9354678012057553dfb764f04798b7c9f6be3..5d476fab2c080e88d234f8f9e865334d478cf330 100644 (file)
@@ -101,7 +101,7 @@ friedman_execute (const struct dataset *ds,
   bool warn = true;
 
   double sigma_t = 0.0;
-  struct datum *row = xcalloc (ost->n_vars, sizeof *row);
+  struct datum *row = XCALLOC (ost->n_vars,  struct datum);
   double rsq;
   struct friedman fr;
   fr.rank_sum = xcalloc (ost->n_vars, sizeof *fr.rank_sum);
index 51232fe160bcd5f64bfd39423ada691d627ee9ed..d7b9b0f084e2de4fc04a5a75d6cd1fbe42e01e60 100644 (file)
@@ -392,8 +392,8 @@ ssq_type1 (struct covariance *cov, gsl_vector *ssq, const struct glm_spec *cmd)
   const gsl_matrix *cm = covariance_calculate_unnormalized (cov);
   size_t i;
   size_t k;
-  bool *model_dropped = xcalloc (covariance_dim (cov), sizeof (*model_dropped));
-  bool *submodel_dropped = xcalloc (covariance_dim (cov), sizeof (*submodel_dropped));
+  bool *model_dropped = XCALLOC (covariance_dim (cov), bool);
+  bool *submodel_dropped = XCALLOC (covariance_dim (cov), bool);
   const struct categoricals *cats = covariance_get_categoricals (cov);
 
   size_t n_dropped_model = 0;
@@ -461,8 +461,8 @@ ssq_type2 (struct covariance *cov, gsl_vector *ssq, const struct glm_spec *cmd)
   const gsl_matrix *cm = covariance_calculate_unnormalized (cov);
   size_t i;
   size_t k;
-  bool *model_dropped = xcalloc (covariance_dim (cov), sizeof (*model_dropped));
-  bool *submodel_dropped = xcalloc (covariance_dim (cov), sizeof (*submodel_dropped));
+  bool *model_dropped = XCALLOC (covariance_dim (cov), bool);
+  bool *submodel_dropped = XCALLOC (covariance_dim (cov), bool);
   const struct categoricals *cats = covariance_get_categoricals (cov);
 
   for (k = 0; k < cmd->n_interactions; k++)
@@ -524,8 +524,8 @@ ssq_type3 (struct covariance *cov, gsl_vector *ssq, const struct glm_spec *cmd)
   const gsl_matrix *cm = covariance_calculate_unnormalized (cov);
   size_t i;
   size_t k;
-  bool *model_dropped = xcalloc (covariance_dim (cov), sizeof (*model_dropped));
-  bool *submodel_dropped = xcalloc (covariance_dim (cov), sizeof (*submodel_dropped));
+  bool *model_dropped = XCALLOC (covariance_dim (cov), bool);
+  bool *submodel_dropped = XCALLOC (covariance_dim (cov), bool);
   const struct categoricals *cats = covariance_get_categoricals (cov);
 
   double ss0;
index 61a05061fdf1a49a2c383299dfab3cf86074d2bc..061857d30e600daa46946bc7ca121324fe7ec805 100644 (file)
@@ -137,7 +137,7 @@ kruskal_wallis_execute (const struct dataset *ds,
 
   int total_n_groups = 0.0;
 
-  struct kw *kw = xcalloc (nst->n_vars, sizeof *kw);
+  struct kw *kw = XCALLOC (nst->n_vars,  struct kw);
 
   /* If the independent variable is missing, then we ignore the case */
   input = casereader_create_filter_missing (input,
index 89559b798fe5dcc32843cd0980027693cff8771b..d9f5ff54fb8974361b239463f70f41394a1e20e5 100644 (file)
@@ -145,7 +145,7 @@ ks_one_sample_execute (const struct dataset *ds,
   int v;
   struct casereader *r = casereader_clone (input);
 
-  struct ks *ks = xcalloc (ost->n_vars, sizeof *ks);
+  struct ks *ks = XCALLOC (ost->n_vars,  struct ks);
 
   for (v = 0; v < ost->n_vars; ++v)
     {
index eced71f9114da17644b05e134503495cfdfb545d..b45f8f910edcfa608a17431afe508d74b94eb1c5 100644 (file)
@@ -94,7 +94,7 @@ mann_whitney_execute (const struct dataset *ds,
   const struct caseproto *proto = casereader_get_proto (input);
   size_t rank_idx = caseproto_get_n_widths (proto);
 
-  struct mw *mw = xcalloc (nst->n_vars, sizeof *mw);
+  struct mw *mw = XCALLOC (nst->n_vars,  struct mw);
 
   for (i = 0; i < nst->n_vars; ++i)
     {
index dbe5813ae48ab7beca5fbd5d4d97349699aa952a..b05f144a74bae96a3c5a6da2b0c9fc38ecfb5205 100644 (file)
@@ -83,7 +83,7 @@ mcnemar_execute (const struct dataset *ds,
 
   struct casereader *r = input;
 
-  struct mcnemar *mc = xcalloc (t2s->n_pairs, sizeof *mc);
+  struct mcnemar *mc = XCALLOC (t2s->n_pairs,  struct mcnemar);
 
   for (i = 0 ; i < t2s->n_pairs; ++i)
     {
index 4138f48161625bdf688763a7dfea872c683d2e46..3c1c28973e3639e1238a2777d3d560fe3c586295 100644 (file)
@@ -537,7 +537,7 @@ populate_table (const struct means *means, const struct mtable *mt,
                 const struct cell *cell,
                 struct pivot_table *pt)
 {
-  size_t *indexes = xcalloc (pt->n_dimensions, sizeof *indexes);
+  size_t *indexes = XCALLOC (pt->n_dimensions, size_t);
   for (int v = 0; v < mt->n_dep_vars; ++v)
     {
       for (int s = 0; s < means->n_statistics; ++s)
index 9cba44dfd556bcd50db351cabb42db13be2a2dea..9c35c15a456aa54820a3faafaa847e5bbbcd3136 100644 (file)
@@ -118,7 +118,7 @@ median_execute (const struct dataset *ds,
   const bool n_sample_test = (value_compare_3way (&nst->val2, &nst->val1,
                                       var_get_width (nst->indep_var)) > 0);
 
-  struct results *results = xcalloc (nst->n_vars, sizeof (*results));
+  struct results *results = XCALLOC (nst->n_vars,  struct results);
   int n_vals = 0;
   for (v = 0; v < nst->n_vars; ++v)
     {
index f0e1715ac3eaafd53a6fe16855092d3f2a730ca4..16a6d72cb96769ad7175dc77243e775db617b4b9 100644 (file)
@@ -712,7 +712,7 @@ do_roc (struct cmd_roc *roc, struct casereader *reader, struct dictionary *dict)
 {
   int i;
 
-  struct roc_state *rs = xcalloc (roc->n_vars, sizeof *rs);
+  struct roc_state *rs = XCALLOC (roc->n_vars,  struct roc_state);
 
   struct casereader *negatives = NULL;
   struct casereader *positives = NULL;
index f5c9979169b9b79ba1ac3ae00a6e47508c20b360..d12bd0d2b52a7239c5d4866bc726edc941e5f6a2 100644 (file)
@@ -116,7 +116,7 @@ runs_execute (const struct dataset *ds,
 
   struct one_sample_test *otp = UP_CAST (test, struct one_sample_test, parent);
   struct runs_test *rt = UP_CAST (otp, struct runs_test, parent);
-  struct run_state *rs = xcalloc (otp->n_vars, sizeof (*rs));
+  struct run_state *rs = XCALLOC (otp->n_vars,  struct run_state);
 
   switch  (rt->cp_mode)
     {
index a832c98b7ea44a8c5bf39b1dee88c3f121a3ff72..52fb4870c39f826e12953a2ab6430ba37d8a62c4 100644 (file)
@@ -138,7 +138,7 @@ sign_execute (const struct dataset *ds,
   const struct two_sample_test *t2s = UP_CAST (test, const struct two_sample_test, parent);
   struct ccase *c;
 
-  struct sign_test_params *stp = xcalloc (t2s->n_pairs, sizeof *stp);
+  struct sign_test_params *stp = XCALLOC (t2s->n_pairs,  struct sign_test_params);
 
   struct casereader *r = input;
 
index b4cb430f198250625a93c0f9334f3b0e07506ce4..ffa2380bb2b1e6125e110787e57cf049057dad12 100644 (file)
@@ -82,7 +82,7 @@ indep_run (struct tt *tt, const struct variable *gvar,
   struct ccase *c;
   struct casereader *r;
 
-  struct pair_stats *ps = xcalloc (tt->n_vars, sizeof *ps);
+  struct pair_stats *ps = XCALLOC (tt->n_vars,  struct pair_stats);
 
   int v;
 
index 0d86bd6c31ad0840ea725a6f626f00c693fa1611..622db2292edc4b0a6cc8f19e44a0c5875ba9315a 100644 (file)
@@ -85,7 +85,7 @@ wilcoxon_execute (const struct dataset *ds,
   const struct dictionary *dict = dataset_dict (ds);
   const struct two_sample_test *t2s = UP_CAST (test, const struct two_sample_test, parent);
 
-  struct wilcoxon_state *ws = xcalloc (t2s->n_pairs, sizeof *ws);
+  struct wilcoxon_state *ws = XCALLOC (t2s->n_pairs,  struct wilcoxon_state);
   const struct variable *weight = dict_get_weight (dict);
   struct variable *weightx = dict_create_internal_var (WEIGHT_IDX, 0);
   struct caseproto *proto;
index c15dac9bbaf65e4363b98c252eaa18d1f5c1f345..ee13422a046cad95519c405042e63003065db716 100644 (file)
@@ -886,7 +886,7 @@ struct mc_results
 static struct mc_results *
 mc_results_create (void)
 {
-  struct mc_results *results = xcalloc (1, sizeof (struct mc_results));
+  struct mc_results *results = XCALLOC (1,  struct mc_results);
   results->stop_reason = MC_CONTINUING;
   gettimeofday (&results->start, NULL);
   return results;
index 7e949fc71804a34b9881b25ba84902696936f20f..4e6d8dad7ad942c633c7dc79820b93bc43d01ea6 100644 (file)
@@ -480,7 +480,7 @@ categoricals_done (const struct categoricals *cat_)
           return;
         }
 
-      struct value_node **nodes = xcalloc (n_vals, sizeof *nodes);
+      struct value_node **nodes = XCALLOC (n_vals,  struct value_node *);
       int x = 0;
       struct value_node *valnd;
       HMAP_FOR_EACH (valnd, struct value_node, node, &vn->valmap)
index 8226b35e47bdd67edbc4e6c923613da5438221ce..158116117f02b0a10ee098d77e8c3d776798fdf8 100644 (file)
@@ -339,7 +339,7 @@ pivot_table_submit_layer (const struct pivot_table *pt,
       out->b = in->color.b;
     }
 
-  struct footnote **footnotes = xcalloc (pt->n_footnotes, sizeof *footnotes);
+  struct footnote **footnotes = XCALLOC (pt->n_footnotes,  struct footnote *);
   for (size_t i = 0; i < pt->n_footnotes; i++)
     {
       const struct pivot_footnote *pf = pt->footnotes[i];
@@ -388,7 +388,7 @@ pivot_table_submit_layer (const struct pivot_table *pt,
                     pt->show_values, pt->show_variables,
                     false, pt->rotate_outer_row_labels);
 
-  size_t *dindexes = xcalloc (pt->n_dimensions, sizeof *dindexes);
+  size_t *dindexes = XCALLOC (pt->n_dimensions, size_t);
   size_t y = 0;
   PIVOT_ENUMERATION_FOR_EACH (pindexes[PIVOT_AXIS_ROW], row_enumeration,
                               &pt->axes[PIVOT_AXIS_ROW])
index a6d55d0a5e48e3372f83f29828dd98786331459c..f2967eae81de9d14ac60dd015b9421112b2c2068 100644 (file)
@@ -1138,7 +1138,7 @@ pivot_table_enumerate_axis (const struct pivot_table *table,
                                                 axis->n_dimensions), 1),
                                   sizeof *enumeration);
   size_t *p = enumeration;
-  size_t *dindexes = xcalloc (table->n_dimensions, sizeof *dindexes);
+  size_t *dindexes = XCALLOC (table->n_dimensions, size_t);
 
   size_t *axis_indexes;
   PIVOT_AXIS_FOR_EACH (axis_indexes, axis)
@@ -1515,7 +1515,7 @@ pivot_table_dump (const struct pivot_table *table, int indentation)
     pivot_dimension_dump (table->dimensions[i], indentation);
 
   /* Presentation and data indexes. */
-  size_t *dindexes = xcalloc (table->n_dimensions, sizeof *dindexes);
+  size_t *dindexes = XCALLOC (table->n_dimensions, size_t);
 
   const struct pivot_axis *layer_axis = &table->axes[PIVOT_AXIS_LAYER];
   if (layer_axis->n_dimensions)
index 8985f35979a1e177abdb507256e42a8c18fa81c6..703d0b1e1e20dd1b4bdd0203b6ad0bac31020fe5 100644 (file)
@@ -347,7 +347,7 @@ spv_legacy_data_decode (const uint8_t *in, size_t size, struct spv_data *out)
       goto error;
     }
 
-  out->sources = xcalloc (lb->n_sources, sizeof *out->sources);
+  out->sources = XCALLOC (lb->n_sources, struct spv_data_source);
   out->n_sources = lb->n_sources;
 
   for (size_t i = 0; i < lb->n_sources; i++)
index 6a8c2d082fd09b2b102e5e5ac37cb18a4ebfaa4c..211813ac1b706dee88b43f452b1108546aabad7f 100644 (file)
@@ -865,7 +865,7 @@ decode_spvdx_derived_variable (const struct spvxml_node *node,
         return &BAD_REFERENCE;
 
       n_values = existing_series->n_values;
-      values = xcalloc (n_values, sizeof *values);
+      values = XCALLOC (n_values, struct spv_data_value);
       for (size_t i = 0; i < n_values; i++)
         values[i].width = -1;
     }
@@ -1638,9 +1638,9 @@ decode_set_cell_properties__ (struct pivot_table *table,
     {
       /* Formatting for individual cells or groups of them with some dimensions
          in common. */
-      int **indexes = xcalloc (table->n_dimensions, sizeof *indexes);
-      size_t *n = xcalloc (table->n_dimensions, sizeof *n);
-      size_t *allocated = xcalloc (table->n_dimensions, sizeof *allocated);
+      int **indexes = XCALLOC (table->n_dimensions, int *);
+      size_t *n = XCALLOC (table->n_dimensions, size_t);
+      size_t *allocated = XCALLOC (table->n_dimensions, size_t);
 
       for (size_t i = 0; i < intersect->n_where; i++)
         {
index be58d416eb8c7a89ba5fe01b58bf62bdefdf737d..7b890a1f65a32dadded174143da01e0d76f97c47 100644 (file)
@@ -565,7 +565,7 @@ decode_spvlb_group (const struct pivot_table *table,
                     struct pivot_dimension *dimension,
                     const char *encoding)
 {
-  category->subs = xcalloc (n_categories, sizeof *category->subs);
+  category->subs = XCALLOC (n_categories, struct pivot_category *);
   category->n_subs = 0;
   category->allocated_subs = 0;
   category->show_label = show_label;
@@ -633,9 +633,8 @@ decode_spvlb_dimension (const struct pivot_table *table,
 
   /* Allocate and fill the array of leaves now that we know how many there
      are. */
-  out->data_leaves = xcalloc (out->n_leaves, sizeof *out->data_leaves);
-  out->presentation_leaves = xcalloc (out->n_leaves,
-                                      sizeof *out->presentation_leaves);
+  out->data_leaves = XCALLOC (out->n_leaves, struct pivot_category *);
+  out->presentation_leaves = XCALLOC (out->n_leaves, struct pivot_category *);
   out->allocated_leaves = out->n_leaves;
   error = fill_leaves (out->root, out);
   if (error)
@@ -689,7 +688,7 @@ decode_spvlb_axis (const uint32_t *dimension_indexes, size_t n_dimensions,
                    enum pivot_axis_type axis_type, struct pivot_table *table)
 {
   struct pivot_axis *axis = &table->axes[axis_type];
-  axis->dimensions = xcalloc (n_dimensions, sizeof *axis->dimensions);
+  axis->dimensions = XCALLOC (n_dimensions, struct pivot_dimension *);
   axis->n_dimensions = n_dimensions;
   axis->extent = 1;
   for (size_t i = 0; i < n_dimensions; i++)
@@ -1004,7 +1003,7 @@ decode_spvlb_table (const struct spvlb_table *in, struct pivot_table **outp)
 
   /* Dimensions. */
   out->n_dimensions = in->dimensions->n_dims;
-  out->dimensions = xcalloc (out->n_dimensions, sizeof *out->dimensions);
+  out->dimensions = XCALLOC (out->n_dimensions, struct pivot_dimension *);
   for (size_t i = 0; i < out->n_dimensions; i++)
     {
       error = decode_spvlb_dimension (out, in->dimensions->dims[i],
index 635941c2d25d55e72be412e4d9c0fad835fe5e6f..4de70352438dbb2bfc1b70add83ced17ad21fb2c 100644 (file)
@@ -1242,7 +1242,7 @@ textfile_create_reader (PsppireImportAssistant *ia)
 
   int i;
 
-  struct fmt_guesser **fg = xcalloc (n_vars, sizeof *fg);
+  struct fmt_guesser **fg = XCALLOC (n_vars,  struct fmt_guesser *);
   for (i = 0 ; i < n_vars; ++i)
     {
       fg[i] = fmt_guesser_create ();