work on crash
authorBen Pfaff <blp@cs.stanford.edu>
Wed, 10 Aug 2022 05:39:10 +0000 (22:39 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Wed, 10 Aug 2022 05:39:14 +0000 (22:39 -0700)
src/language/stats/ctables.c
tests/language/stats/ctables.at

index da511b69510f16bc7fb9d303392f7d719a1f4c55..2833ce6b519911419408066728faa81cf50c375f 100644 (file)
@@ -4362,6 +4362,8 @@ ctables_format (double d, const struct fmt_spec *format,
 static void
 ctables_table_output (struct ctables *ct, struct ctables_table *t)
 {
+  printf ("\n");
+
   struct pivot_table *pt = pivot_table_create__ (
     (t->title
      ? pivot_value_new_user_text (t->title, SIZE_MAX)
@@ -4379,6 +4381,7 @@ ctables_table_output (struct ctables *ct, struct ctables_table *t)
                                 && t->summary_specs.n > 1));
   if (summary_dimension)
     {
+      printf ("summary_dimension\n");
       struct pivot_dimension *d = pivot_dimension_create (
         pt, t->slabels_axis, N_("Statistics"));
       const struct ctables_summary_spec_set *specs = &t->summary_specs;
@@ -4392,6 +4395,7 @@ ctables_table_output (struct ctables *ct, struct ctables_table *t)
   bool categories_dimension = t->clabels_example != NULL;
   if (categories_dimension)
     {
+      printf ("categories_dimension\n");
       struct pivot_dimension *d = pivot_dimension_create (
         pt, t->label_axis[t->clabels_from_axis],
         t->clabels_from_axis == PIVOT_AXIS_ROW
@@ -4414,17 +4418,9 @@ ctables_table_output (struct ctables *ct, struct ctables_table *t)
   struct pivot_dimension *d[PIVOT_N_AXES];
   for (enum pivot_axis_type a = 0; a < PIVOT_N_AXES; a++)
     {
-      static const char *names[] = {
-        [PIVOT_AXIS_ROW] = N_("Rows"),
-        [PIVOT_AXIS_COLUMN] = N_("Columns"),
-        [PIVOT_AXIS_LAYER] = N_("Layers"),
-      };
-      d[a] = (t->axes[a] || a == t->summary_axis
-              ? pivot_dimension_create (pt, a, names[a])
-              : NULL);
-      if (!d[a])
+      d[a] = NULL;
+      if (!t->axes[a] && a != t->summary_axis)
         continue;
-
       assert (t->axes[a]);
 
       for (size_t i = 0; i < t->stacks[a].n; i++)
@@ -4536,6 +4532,17 @@ ctables_table_output (struct ctables *ct, struct ctables_table *t)
               };
             }
 
+          if (!n_levels)
+            goto next_free;
+
+          static const char *names[] = {
+            [PIVOT_AXIS_ROW] = N_("Rows"),
+            [PIVOT_AXIS_COLUMN] = N_("Columns"),
+            [PIVOT_AXIS_LAYER] = N_("Layers"),
+          };
+          d[a] = pivot_dimension_create (pt, a, names[a]);
+          printf ("%s dimension\n", names[a]);
+
           /* Pivot categories:
 
              - variable label for nest->vars[0], if vlabel != CTVL_NONE
@@ -4633,8 +4640,9 @@ ctables_table_output (struct ctables *ct, struct ctables_table *t)
 
               cell->axes[a].leaf = prev_leaf;
             }
-          free (sorted);
           free (groups);
+        next_free:
+          free (sorted);
           free (levels);
           free (sections);
         }
index 726da3d723c4e3fc50060a329306ead40e143f6c..a60ec46b227109aad0d201a4465412f06dc63531 100644 (file)
@@ -2964,6 +2964,15 @@ AT_SETUP([CTABLES scale summary functions - assertion failure])
 AT_CHECK([ln $top_srcdir/examples/nhtsa.sav . || cp $top_srcdir/examples/nhtsa.sav .])
 AT_DATA([ctables.sps],
 [[GET 'nhtsa.sav'.
+CTABLES
+    /VLABELS VARIABLE=qn19a DISPLAY=BOTH
+    /TABLE region BY qn19a
+    /CATEGORIES VARIABLES=qn19a TOTAL=YES MISSING=INCLUDE
+    /SLABELS POSITION=ROW.
+CTABLES
+    /VLABELS VARIABLE=qn19a DISPLAY=NONE
+    /TABLE region BY qn19a
+    /CATEGORIES VARIABLES=qn19a TOTAL=YES MISSING=INCLUDE.
 CTABLES
     /VLABELS VARIABLE=qn19a DISPLAY=NONE
     /TABLE region BY qn19a