From: Ben Pfaff Date: Tue, 26 Oct 2010 05:52:10 +0000 (-0700) Subject: CROSSTABS: Handle case where all cases in a crosstabulation are missing. X-Git-Tag: v0.7.7~174 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dc9318cc16bfa8aba02cc0f364b1ca3a7cf1de9d;p=pspp-builds.git CROSSTABS: Handle case where all cases in a crosstabulation are missing. Thanks to Michel Boaventura for reporting the problem. Bug #31260. --- diff --git a/src/language/stats/crosstabs.q b/src/language/stats/crosstabs.q index be096bc4..189e7182 100644 --- a/src/language/stats/crosstabs.q +++ b/src/language/stats/crosstabs.q @@ -908,9 +908,7 @@ static void table_value_missing (struct crosstabs_proc *proc, static void delete_missing (struct pivot_table *); static void build_matrix (struct pivot_table *); -/* Output pivot table beginning at PB and continuing until PE, - exclusive. For efficiency, *MATP is a pointer to a matrix that can - hold *MAXROWS entries. */ +/* Output pivot table PT in the context of PROC. */ static void output_pivot_table (struct crosstabs_proc *proc, struct pivot_table *pt) { @@ -924,6 +922,24 @@ output_pivot_table (struct crosstabs_proc *proc, struct pivot_table *pt) enum_var_values (pt, COL_VAR, &pt->cols, &pt->n_cols, proc->descending); + if (pt->n_cols == 0) + { + struct string vars; + int i; + + ds_init_cstr (&vars, var_get_name (pt->vars[0])); + for (i = 1; i < pt->n_vars; i++) + ds_put_format (&vars, " * %s", var_get_name (pt->vars[i])); + + /* TRANSLATORS: The %s here describes a crosstabulation. It takes the + form "var1 * var2 * var3 * ...". */ + msg (SW, _("Crosstabulation %s contained no non-missing cases."), + ds_cstr (&vars)); + + ds_destroy (&vars); + return; + } + if (proc->cells) table = create_crosstab_table (proc, pt); if (proc->statistics & (1u << CRS_ST_CHISQ)) diff --git a/tests/language/stats/crosstabs.at b/tests/language/stats/crosstabs.at index b0da517f..2657cc45 100644 --- a/tests/language/stats/crosstabs.at +++ b/tests/language/stats/crosstabs.at @@ -378,3 +378,26 @@ x,2.00,1.00,Total Total,4.0,2.0,6.0 ]]) AT_CLEANUP + +# Bug #31260. +AT_SETUP([CROSSTABS crash when all cases missing]) +AT_DATA([crosstabs.sps], [dnl +DATA LIST LIST NOTABLE /X1 X2. +BEGIN DATA. +1 1 +END DATA. + +MISSING VALUES x2 (1). + +CROSSTABS /TABLES= X1 by X2. +]) +AT_CHECK([pspp -O format=csv crosstabs.sps], [0], [dnl +Table: Summary. +,Cases,,,,, +,Valid,,Missing,,Total, +,N,Percent,N,Percent,N,Percent +X1 * X2,0,0.0%,1,100.0%,1,100.0% + +crosstabs.sps:8: warning: CROSSTABS: Crosstabulation X1 * X2 contained no non-missing cases. +]) +AT_CLEANUP