pivot-table: Avoid null dereference in "pspp-output dump" in corner cases.
authorBen Pfaff <blp@cs.stanford.edu>
Tue, 5 Apr 2022 15:15:45 +0000 (08:15 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Tue, 5 Apr 2022 15:15:45 +0000 (08:15 -0700)
src/output/pivot-table.c

index 6ba4c16f2e0811545b4b5673678900f5b37a1cf3..4744e66c4b936db575e4b62509be369b7cf488ab 100644 (file)
@@ -1939,6 +1939,8 @@ compose_headings (const struct pivot_table *pt,
 static void
 free_headings (const struct pivot_axis *axis, char ***headings)
 {
+  if (!headings)
+    return;
   for (size_t i = 0; i < axis->label_depth; i++)
     {
       for (size_t j = 0; j < axis->extent; j++)
@@ -2103,7 +2105,7 @@ pivot_table_dump (const struct pivot_table *table, int indentation)
             {
               if (x)
                 fputs ("; ", stdout);
-              if (column_headings[y][x])
+              if (column_headings && column_headings[y] && column_headings[y][x])
                 fputs (column_headings[y][x], stdout);
             }
           putchar ('\n');