From: Ben Pfaff Date: Mon, 17 Jan 2022 22:05:09 +0000 (-0800) Subject: pivot-table: Fix pivot_table_dump() null pointer dereference in special case. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pspp;a=commitdiff_plain;h=c0556bae97db87ff3748d7cbdff0223933d532ec pivot-table: Fix pivot_table_dump() null pointer dereference in special case. This function only gets called from "pspp-output dump", so it's not a very important bug. --- diff --git a/src/output/pivot-table.c b/src/output/pivot-table.c index a3325a1469..37a092d335 100644 --- a/src/output/pivot-table.c +++ b/src/output/pivot-table.c @@ -2131,21 +2131,30 @@ pivot_table_dump (const struct pivot_table *table, int indentation) size_t *row_enumeration = pivot_table_enumerate_axis ( table, PIVOT_AXIS_ROW, layer_indexes, table->look->omit_empty, NULL); + /* Print column headings. + + Ordinarily the test for nonnull 'column_headings' would be + unnecessary, because 'column_headings' is null only if the axis's + label_depth is 0, but there is a special case for the column axis only + in pivot_table_assign_label_depth(). */ char ***column_headings = compose_headings ( table, &table->axes[PIVOT_AXIS_COLUMN], column_enumeration); - for (size_t y = 0; y < table->axes[PIVOT_AXIS_COLUMN].label_depth; y++) + if (column_headings) { - indent (indentation + 1); - for (size_t x = 0; x < table->axes[PIVOT_AXIS_COLUMN].extent; x++) + for (size_t y = 0; y < table->axes[PIVOT_AXIS_COLUMN].label_depth; y++) { - if (x) - fputs ("; ", stdout); - if (column_headings[y][x]) - fputs (column_headings[y][x], stdout); + indent (indentation + 1); + for (size_t x = 0; x < table->axes[PIVOT_AXIS_COLUMN].extent; x++) + { + if (x) + fputs ("; ", stdout); + if (column_headings[y][x]) + fputs (column_headings[y][x], stdout); + } + putchar ('\n'); } - putchar ('\n'); + free_headings (&table->axes[PIVOT_AXIS_COLUMN], column_headings); } - free_headings (&table->axes[PIVOT_AXIS_COLUMN], column_headings); indent (indentation + 1); printf ("-----------------------------------------------\n");