pivot-output: Fix crash when layers axis has no leaves.
authorBen Pfaff <blp@cs.stanford.edu>
Fri, 3 May 2024 21:45:11 +0000 (14:45 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Fri, 3 May 2024 21:48:34 +0000 (14:48 -0700)
Thanks to Zhou Geng for reporting this bug as poc6 in the report here:
https://lists.gnu.org/archive/html/bug-gnu-pspp/2024-03/msg00015.html

src/output/pivot-output.c
tests/language/commands/ctables.at

index 3666ffbcee00b0c88df8b1f8743cff77b094e1f0..35aac25a09f54c79ccd93670928885c5bfc941d8 100644 (file)
@@ -41,7 +41,7 @@ pivot_output_next_layer (const struct pivot_table *pt, size_t *indexes,
   const struct pivot_axis *layer_axis = &pt->axes[PIVOT_AXIS_LAYER];
   if (print && pt->look->print_all_layers)
     return pivot_axis_iterator_next (indexes, layer_axis);
-  else if (!indexes)
+  else if (!indexes && layer_axis->extent)
     {
       size_t size = layer_axis->n_dimensions * sizeof *pt->current_layer;
       return size ? xmemdup (pt->current_layer, size) : xmalloc (1);
index b71695f759025f6e462e901dc3d5eb591302b8e4..4757d4ea0c3cddb7cc175f9dd7db34cc33a037ec 100644 (file)
@@ -6044,3 +6044,22 @@ AT_CHECK([pspp ctables.sps -O box=unicode -O width=80], [0], [dnl
 ╰──────┴────────┴──────────────┴─────┴─────┴─────────┴────────────┴────────────╯
 ])
 AT_CLEANUP
+
+AT_SETUP([CTABLES crash with all-missing data])
+AT_DATA([ctables.sps], [dnl
+DATA LIST LIST NOTABLE/a.
+BEGIN DATA.
+.
+END DATA.
+
+* The final one below previously crashed.
+CTABLES/TAB A.
+CTABLES/TAB BY A.
+CTABLES/TAB BY BY A.
+])
+AT_CHECK([pspp ctables.sps -O box=unicode -O width=80], [0], [dnl
+Custom Tables
+
+Custom Tables
+])
+AT_CLEANUP
\ No newline at end of file