X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fstats%2Fcrosstabs.q;h=3bffa2a32f5839f712548f8f07e4f765fe719c6c;hb=a675bf52fd2ed392ff50f0f86e0efd6aefa29a03;hp=e57d9343c724ec96b2cb5badf2ec5eaa1fed48c1;hpb=43b1296aafe7582e7dbe6c2b6a8b478d7d9b0fcf;p=pspp diff --git a/src/language/stats/crosstabs.q b/src/language/stats/crosstabs.q index e57d9343c7..3bffa2a32f 100644 --- a/src/language/stats/crosstabs.q +++ b/src/language/stats/crosstabs.q @@ -46,13 +46,10 @@ #include #include #include -#include #include #include #include #include -#include -#include #include #include #include @@ -61,6 +58,8 @@ #include #include "minmax.h" +#include "xalloc.h" +#include "xmalloca.h" #include "gettext.h" #define _(msgid) gettext (msgid) @@ -191,11 +190,16 @@ int cmd_crosstabs (struct lexer *lexer, struct dataset *ds) { int result = internal_cmd_crosstabs (lexer, ds); + int i; free (variables); pool_destroy (pl_tc); pool_destroy (pl_col); + for (i = 0; i < nxtab; i++) + free (xtab[i]); + free (xtab); + return result; } @@ -356,7 +360,7 @@ crs_custom_tables (struct lexer *lexer, struct dataset *ds, struct cmd_crosstabs goto done; if (xalloc_oversized (nx, by_nvar[n_by])) { - msg (SE, _("Too many crosstabulation variables or dimensions.")); + msg (SE, _("Too many cross-tabulation variables or dimensions.")); goto done; } nx *= by_nvar[n_by]; @@ -516,10 +520,11 @@ precalc (struct casereader *input, const struct dataset *ds) { struct ccase c; - if (!casereader_peek (input, 0, &c)) - return; - output_split_file_values (ds, &c); - case_destroy (&c); + if (casereader_peek (input, 0, &c)) + { + output_split_file_values (ds, &c); + case_destroy (&c); + } if (mode == GENERAL) { @@ -547,7 +552,7 @@ precalc (struct casereader *input, const struct dataset *ds) sorted_tab = xnrealloc (sorted_tab, n_sorted_tab + count, sizeof *sorted_tab); - v = local_alloc (sizeof *v * x->nvar); + v = xmalloca (sizeof *v * x->nvar); for (j = 2; j < x->nvar; j++) v[j] = get_var_range (x->vars[j])->min; for (j = 0; j < count; j++) @@ -581,7 +586,7 @@ precalc (struct casereader *input, const struct dataset *ds) break; } } - local_free (v); + freea (v); } sorted_tab = xnrealloc (sorted_tab, @@ -611,7 +616,7 @@ calc_general (struct ccase *c, const struct dataset *ds) struct crosstab *x = xtab[t]; const size_t entry_size = (sizeof (struct table_entry) + sizeof (union value) * (x->nvar - 1)); - struct table_entry *te = local_alloc (entry_size); + struct table_entry *te = xmalloca (entry_size); /* Construct table entry for the current record and table. */ te->table = t; @@ -660,7 +665,7 @@ calc_general (struct ccase *c, const struct dataset *ds) } next_crosstab: - local_free (te); + freea (te); } } @@ -822,6 +827,16 @@ postcalc (void) } hsh_destroy (gen_tab); + if (mode == INTEGER) + { + int i; + for (i = 0; i < n_sorted_tab; i++) + { + free (sorted_tab[i]->u.data); + free (sorted_tab[i]); + } + free (sorted_tab); + } } static void insert_summary (struct tab_table *, int tab_index, double valid); @@ -910,7 +925,7 @@ insert_summary (struct tab_table *t, int tab_index, double valid) /* Crosstabulation name. */ { - char *buf = local_alloc (128 * x->nvar); + char *buf = xmalloca (128 * x->nvar); char *cp = buf; int i; @@ -923,7 +938,7 @@ insert_summary (struct tab_table *t, int tab_index, double valid) } tab_text (t, 0, 0, TAB_LEFT, buf); - local_free (buf); + freea (buf); } /* Counts and percentages. */ @@ -1050,7 +1065,7 @@ output_pivot_table (struct table_entry **pb, struct table_entry **pe, /* Title. */ { - char *title = local_alloc (x->nvar * 64 + 128); + char *title = xmalloca (x->nvar * 64 + 128); char *cp = title; int i; @@ -1116,7 +1131,7 @@ output_pivot_table (struct table_entry **pb, struct table_entry **pe, strcpy (cp, "]."); tab_title (table, "%s", title); - local_free (title); + freea (title); } tab_offset (table, 0, 2); @@ -2720,8 +2735,8 @@ calc_symmetric (double v[N_SYMMETRIC], double ase[N_SYMMETRIC], /* Spearman correlation, Pearson's r. */ if (cmd.a_statistics[CRS_ST_CORR]) { - double *R = local_alloc (sizeof *R * n_rows); - double *C = local_alloc (sizeof *C * n_cols); + double *R = xmalloca (sizeof *R * n_rows); + double *C = xmalloca (sizeof *C * n_cols); { double y, t, c = 0., s = 0.; @@ -2760,8 +2775,8 @@ calc_symmetric (double v[N_SYMMETRIC], double ase[N_SYMMETRIC], calc_r (R, C, &v[6], &t[6], &ase[6]); t[6] = v[6] / t[6]; - local_free (R); - local_free (C); + freea (R); + freea (C); calc_r ((double *) rows, (double *) cols, &v[7], &t[7], &ase[7]); t[7] = v[7] / t[7];