From 4c33fdc0eb2367eb2028b2d620af5444b44ae6bf Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 6 Mar 2024 14:32:41 -0800 Subject: [PATCH] CROSSTABS: Fix tabular output when columns or rows are empty. Thanks to Andreas Hammer for reporting the bug. --- src/language/commands/crosstabs.c | 4 +--- tests/language/commands/crosstabs.at | 14 +++++++------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/language/commands/crosstabs.c b/src/language/commands/crosstabs.c index f662de2b49..d5c055c21f 100644 --- a/src/language/commands/crosstabs.c +++ b/src/language/commands/crosstabs.c @@ -1712,7 +1712,6 @@ display_crosstabulation (struct crosstabs_proc *proc, indexes[i + 3] = xt->const_indexes[i]; /* Put in the actual cells. */ - double *mp = xt->mat; for (size_t r = 0; r < n_rows; r++) { if (!xt->row_tot[r] && proc->mode != INTEGER) @@ -1726,6 +1725,7 @@ display_crosstabulation (struct crosstabs_proc *proc, indexes[COL_VAR + 1] = c; + double *mp = xt->mat + r * n_cols + c; double expected_value = xt->row_tot[r] * xt->col_tot[c] / xt->total; double residual = *mp - expected_value; double sresidual = residual / sqrt (expected_value); @@ -1750,8 +1750,6 @@ display_crosstabulation (struct crosstabs_proc *proc, pivot_table_put (table, indexes, table->n_dimensions, pivot_value_new_number (entries[cell])); } - - mp++; } } diff --git a/tests/language/commands/crosstabs.at b/tests/language/commands/crosstabs.at index f6cc80b9e8..8a3b1a15d4 100644 --- a/tests/language/commands/crosstabs.at +++ b/tests/language/commands/crosstabs.at @@ -446,14 +446,14 @@ Table: x × y × z ,,,,,y,,Total ,,,,,1,2, z,1,x,1,Count,1,0,1 -,,,3,Count,0,0,1 -,,,5,Count,1,0,1 -,,,7,Count,0,0,1 -,,,8,Count,0,1,1 +,,,3,Count,1,0,1 +,,,5,Count,0,1,1 +,,,7,Count,1,0,1 +,,,8,Count,1,0,1 ,,Total,,Count,4,1,5 -,2,x,2,Count,0,0,1 -,,,4,Count,0,1,1 -,,,6,Count,0,0,1 +,2,x,2,Count,0,1,1 +,,,4,Count,1,0,1 +,,,6,Count,1,0,1 ,,,9,Count,1,0,1 ,,Total,,Count,3,1,4 -- 2.30.2