From: Ben Pfaff Date: Fri, 3 Jul 2009 18:34:26 +0000 (-0700) Subject: Fix segfault drawing pie charts with old versions of libplot. X-Git-Tag: v0.6.2-pre3~2 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=49a428e6e922f86b94f8559347d3fb90031b119a;p=pspp-builds.git Fix segfault drawing pie charts with old versions of libplot. If chart_create returned null, we dereferenced a null pointer just below. Avoid doing this. Also add similar fixes to other code that calls chart_create. It may not be necessary in every case. Reported by Jason Stover. --- diff --git a/src/language/stats/examine.q b/src/language/stats/examine.q index 4254d4fb..592bb56b 100644 --- a/src/language/stats/examine.q +++ b/src/language/stats/examine.q @@ -1797,6 +1797,9 @@ box_plot_variables (const struct factor *fctr, double y_min = DBL_MAX; double y_max = -DBL_MAX; struct chart *ch = chart_create (); + if (ch == NULL) + break; + ds_init_empty (&str); factor_to_string (fctr, *fs, 0, &str ); @@ -1852,6 +1855,8 @@ box_plot_group (const struct factor *fctr, struct chart *ch; ch = chart_create (); + if (ch == NULL) + break; boxplot_draw_yscale (ch, totals[i].max, totals[i].min); diff --git a/src/output/charts/piechart.c b/src/output/charts/piechart.c index aa52f99e..d7db80e9 100644 --- a/src/output/charts/piechart.c +++ b/src/output/charts/piechart.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -57,22 +57,26 @@ piechart_plot(const char *title, const struct slice *slices, int n_slices) int i; double total_magnetude=0; - struct chart *ch = chart_create(); + struct chart *ch; - const double left_label = ch->data_left + - (ch->data_right - ch->data_left)/10.0; + double left_label; + double right_label; - const double right_label = ch->data_right - - (ch->data_right - ch->data_left)/10.0; + double centre_x; + double centre_y; - const double centre_x = (ch->data_right + ch->data_left ) / 2.0 ; - const double centre_y = (ch->data_top + ch->data_bottom ) / 2.0 ; + double radius; - const double radius = MIN( - 5.0 / 12.0 * (ch->data_top - ch->data_bottom), - 1.0 / 4.0 * (ch->data_right - ch->data_left) - ); + ch = chart_create (); + if (ch == NULL) + return; + left_label = ch->data_left + (ch->data_right - ch->data_left)/10.0; + right_label = ch->data_right - (ch->data_right - ch->data_left)/10.0; + centre_x = (ch->data_right + ch->data_left ) / 2.0; + centre_y = (ch->data_top + ch->data_bottom ) / 2.0; + radius = MIN (5.0 / 12.0 * (ch->data_top - ch->data_bottom), + 1.0 / 4.0 * (ch->data_right - ch->data_left)); chart_write_title(ch, "%s", title); diff --git a/src/output/charts/plot-hist.c b/src/output/charts/plot-hist.c index b567370c..88ad0899 100644 --- a/src/output/charts/plot-hist.c +++ b/src/output/charts/plot-hist.c @@ -117,6 +117,9 @@ histogram_plot(const gsl_histogram *hist, struct chart *ch; ch = chart_create(); + if (ch == NULL) + return; + chart_write_title(ch, _("HISTOGRAM")); chart_write_ylabel(ch, _("Frequency"));