totals can go first as well as last
authorBen Pfaff <blp@cs.stanford.edu>
Tue, 4 Jan 2022 07:04:00 +0000 (23:04 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 13 Mar 2022 23:56:02 +0000 (16:56 -0700)
src/language/stats/ctables.c

index 9c5b8ee6149d85e6aa5558cdb498466dcd06639e..18fd30b683b3a438dd41036f2a596773a18b53cc 100644 (file)
@@ -2127,8 +2127,11 @@ ctables_categories_match (const struct ctables_categories *c,
 static const struct ctables_category *
 ctables_categories_total (const struct ctables_categories *c)
 {
-  const struct ctables_category *total = &c->cats[c->n_cats - 1];
-  return total->type == CCT_TOTAL ? total : NULL;
+  const struct ctables_category *first = &c->cats[0];
+  const struct ctables_category *last = &c->cats[c->n_cats - 1];
+  return (first->type == CCT_TOTAL ? first
+          : last->type == CCT_TOTAL ? last
+          : NULL);
 }
 
 static void