EXAMINE: Don't crash when unrenderable graphs are requested.
authorJohn Darrington <john@darrington.wattle.id.au>
Sat, 4 May 2019 04:29:44 +0000 (06:29 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 4 May 2019 04:38:27 +0000 (06:38 +0200)
This change fixes a crash in the cleanup of the cairo driver when
a graph which is not representable was attempted to be rendered.

src/output/charts/np-plot.c
src/output/driver.c
src/ui/terminal/main.c
tests/language/stats/examine.at

index ccccbeff36ae192b844a3f95b25aa6ca9c4b6534..a140230e06282ed306ccf86e823e6a2d698a020c 100644 (file)
@@ -33,7 +33,7 @@ make_np_plot (const struct np *np, const struct casereader *reader,
 {
   struct np_plot_chart *npp;
 
-  if (np->n < 1.0)
+  if (np->n <= 1.0)
     return NULL;
 
   npp = xzalloc (sizeof *npp);
index da448b31707c8154c8ad2e3f99d0342c0115500d..44aa2558247394b3c81f6f5341ebead2ca501437 100644 (file)
@@ -76,6 +76,8 @@ static struct output_engine *
 engine_stack_top (void)
 {
   struct ll *head = ll_head (&engine_stack);
+  if (ll_is_empty (head))
+    return NULL;
   return ll_data (head, struct output_engine, ll);
 }
 
@@ -202,6 +204,9 @@ output_submit (struct output_item *item)
 {
   struct output_engine *e = engine_stack_top ();
 
+  if (e == NULL)
+    return;
+
   if (item == NULL)
     return;
 
@@ -262,6 +267,9 @@ const char *
 output_get_command_name (void)
 {
   struct output_engine *e = engine_stack_top ();
+  if (e == NULL)
+    return NULL;
+
   for (size_t i = e->n_groups; i-- > 0; )
     if (e->groups[i])
       return e->groups[i];
index 4609e4eded20f39fc93e74e4d432b4de25ee4772..c78756383adbd1d590bd6ffe965e46837eb0820d 100644 (file)
@@ -160,13 +160,13 @@ main (int argc, char **argv)
     }
 
 
+  output_engine_pop ();
   session_destroy (the_session);
 
   random_done ();
   settings_done ();
   fh_done ();
   lex_destroy (lexer);
-  output_engine_pop ();
   i18n_done ();
 
   return msg_ui_any_errors ();
index b2afe616b86f5750e670d03b23adb561b885a0aa..dbd11437fd55899d57be826608bb954de6a38c6b 100644 (file)
@@ -1,5 +1,5 @@
 dnl PSPP - a program for statistical analysis.
-dnl Copyright (C) 2017 Free Software Foundation, Inc.
+dnl Copyright (C) 2017, 2019 Free Software Foundation, Inc.
 dnl 
 dnl This program is free software: you can redistribute it and/or modify
 dnl it under the terms of the GNU General Public License as published by
@@ -1250,3 +1250,18 @@ Weight in kilograms ,Highest,1,13,92.1
 ])
 AT_CLEANUP
 
+
+AT_SETUP([EXAMINE -- Crash on unrepresentable graphs])
+AT_DATA([examine.sps], [dnl
+data list notable list /x * g *.
+begin data.
+96 1
+end data.
+
+examine x  by g
+        /nototal
+        /plot = all.
+])
+dnl This bug only manifested itself on cairo based drivers.
+AT_CHECK([pspp -O format=pdf examine.sps], [1], [ignore])
+AT_CLEANUP