Fixed bug where an empty chart (one with no data) would crash.
authorJohn Darrington <john@darrington.wattle.id.au>
Thu, 18 Feb 2016 05:51:07 +0000 (06:51 +0100)
committerJohn Darrington <john@darrington.wattle.id.au>
Thu, 18 Feb 2016 05:51:07 +0000 (06:51 +0100)
Reported by: Friedrich Beckmann
Fixes bug: #47181

src/output/charts/boxplot.c
src/output/driver.c
tests/output/charts.at

index deabc1fa6e8f059c026c5c079b6e4a60f43b0b5a..0a933195d04e59adbab217c5e52ed6743d41d0e0 100644 (file)
@@ -25,6 +25,8 @@
 struct boxplot *
 boxplot_create (double y_min, double y_max, const char *title)
 {
+  if (y_min >= y_max)
+    return NULL;
   struct boxplot *boxplot = xmalloc (sizeof *boxplot);
   chart_item_init (&boxplot->chart_item, &boxplot_class, title);
   boxplot->y_min = y_min;
@@ -38,6 +40,9 @@ void
 boxplot_add_box (struct boxplot *boxplot,
                  struct box_whisker *bw, const char *label)
 {
+  if (boxplot == NULL)
+    return;
+
   struct boxplot_box *box;
   if (boxplot->n_boxes >= boxplot->boxes_allocated)
     boxplot->boxes = x2nrealloc (boxplot->boxes, &boxplot->boxes_allocated,
@@ -51,6 +56,9 @@ static void
 boxplot_chart_destroy (struct chart_item *chart_item)
 {
   struct boxplot *boxplot = to_boxplot (chart_item);
+  if (boxplot == NULL)
+    return;
+
   size_t i;
 
   for (i = 0; i < boxplot->n_boxes; i++)
index 6f72ffe739aca687e07bfbd1bb4a92be5c1fd92d..81ef6690e5bcf3de7f88fcab4325ed4b3eeb0f69 100644 (file)
@@ -159,6 +159,9 @@ output_submit (struct output_item *item)
 {
   struct output_engine *e = engine_stack_top ();
 
+  if (item == NULL)
+    return;
+
   if (is_syntax_item (item))
     {
       ds_put_cstr (&e->deferred_syntax, text_item_get_text (to_text_item (item)));
index 7cbaeb2e823fc5ed78adf454743f0b91bddaf1f4..59ad8ca319a9584780ea0e36572d0538ad274865 100644 (file)
@@ -235,3 +235,37 @@ CROSSTABS
 AT_CHECK([pspp  -o pspp.txt xxx.sps], [0], [ignore])
 
 AT_CLEANUP
+
+
+
+
+AT_SETUP([BOXPLOT Empty])
+AT_DATA([bp.sps],[
+DATA LIST LIST /X * Y * .
+BEGIN DATA
+1
+2
+2
+2
+3
+END DATA
+
+EXAMINE
+    /VARIABLES = Y
+    /PLOT = BOXPLOT.
+])
+
+
+AT_CHECK([pspp -o pspp.txt bp.sps], [0], [ignore])
+
+AT_CLEANUP
+
+
+
+
+
+
+
+
+
+