CTABLES: Don't crash for attempting to apply a summary to nested variables.
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 28 May 2023 06:18:31 +0000 (23:18 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 28 May 2023 06:18:31 +0000 (23:18 -0700)
Thanks to Matthias Faeth for reporting this bug.

src/language/commands/ctables.c
tests/language/commands/ctables.at

index 78b5616c1f3610add4c472c1f91ce93d15e411e7..fc429e1f36aab879fc51d0be568b4b229aec785e 100644 (file)
@@ -1201,8 +1201,16 @@ add_summary_spec (struct ctables_axis *axis,
       };
       return true;
     }
+  else if (axis->op == CTAO_NEST)
+    {
+      msg_at (SE, loc, _("Summary functions may not be applied to the nest "
+                         "operator '>'."));
+      msg_at (SN, axis->loc, _("This is where the nest operator was used."));
+      return false;
+    }
   else
     {
+      assert (axis->op == CTAO_STACK);
       for (size_t i = 0; i < 2; i++)
         if (!add_summary_spec (axis->subs[i], function, weighting, area,
                                percentile, label, format, is_ctables_format,
index d0bf368fecd537a4241df9f69401f0b8a00bb62c..9dd5c0e5e83de00ec96a3a6d0fe28457a92cd9d0 100644 (file)
@@ -741,6 +741,8 @@ CTABLES /TABLE qn113 [COUNT.UCL].
 CTABLES /TABLE qn1 /CATEGORIES **.
 
 CTABLES /TITLES.
+
+CTABLES /TABLE (qn1 > qn113) [COUNT].
 ]])
 AT_CHECK([pspp ctables.sps -O box=unicode -O width=120], [1],
 [[ctables.sps:2.76-2.78: error: CTABLES: Computed category &pc references a category not included in the category list.
@@ -888,6 +890,14 @@ PCOMPUTE, PPROPERTIES, WEIGHT, HIDESMALLCOUNTS, TABLE.
 ctables.sps:36.10-36.15: note: CTABLES: TABLE must appear before this subcommand.
    36 | CTABLES /TITLES.
       |          ^~~~~~
+
+ctables.sps:38.31-38.35: error: CTABLES: Summary functions may not be applied to the nest operator '>'.
+   38 | CTABLES /TABLE (qn1 > qn113) [COUNT].
+      |                               ^~~~~
+
+ctables.sps:38.17-38.27: note: CTABLES: This is where the nest operator was used.
+   38 | CTABLES /TABLE (qn1 > qn113) [COUNT].
+      |                 ^~~~~~~~~~~
 ]])
 AT_CLEANUP