limit the number of variables in barchart from crosstabs #58968
authorFriedrich Beckmann <friedrich.beckmann@gmx.de>
Mon, 17 Aug 2020 17:43:37 +0000 (19:43 +0200)
committerFriedrich Beckmann <friedrich.beckmann@gmx.de>
Mon, 17 Aug 2020 17:43:37 +0000 (19:43 +0200)
The barchart was created with more than two variables from
the crosstabs subcommand. I added an assertion and limit
the number of variables to two. This bug resulted in a
regression failure (crash) for test

493: CROSSTABS barchart

on i386 architecture.

see: https://savannah.gnu.org/bugs/?58968

src/language/stats/crosstabs.q
src/output/charts/barchart.c

index 11e76cd1da3bb635b45b53180f2b9ed016d823bf..e8739bc1bf438d2616fcbde50c8986bbeae77912 100644 (file)
@@ -782,10 +782,11 @@ postcalc (struct crosstabs_proc *proc)
         }
       if (proc->barchart)
         {
-          const struct variable **vars = xcalloc (xt->n_vars, sizeof *vars);
-          for (size_t i = 0; i < xt->n_vars; i++)
+          int n_vars = (xt->n_vars > 2 ? 2 : xt->n_vars);
+          const struct variable **vars = xcalloc (n_vars, sizeof *vars);
+          for (size_t i = 0; i < n_vars; i++)
             vars[i] = xt->vars[i].var;
-          chart_item_submit (barchart_create (vars, xt->n_vars, _("Count"),
+          chart_item_submit (barchart_create (vars, n_vars, _("Count"),
                                               false,
                                               xt->entries, xt->n_entries));
           free (vars);
index da72fc89f87b84e3b7e3a4b33da38304792ad69f..1b7e83ca4fc1978d62e43acc70c6bffc8c544786 100644 (file)
@@ -160,7 +160,7 @@ barchart_create (const struct variable **var, int n_vars,
 
   int width = var_get_width (var[pidx]);
 
-  assert (n_vars >= 1);
+  assert (n_vars >= 1 && n_vars <= 2);
 
   bar = xzalloc (sizeof *bar);
   bar->percent = percent;