From: John Darrington Date: Thu, 2 Apr 2009 00:19:09 +0000 (+0800) Subject: Fixed bug where piecharts with many segments crashed. X-Git-Tag: v0.6.2-pre1~10 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pspp-builds.git;a=commitdiff_plain;h=23fe9f40872f54400ce10d87f349c8d317c21274 Fixed bug where piecharts with many segments crashed. Make sure that we don't index beyond the bounds of the data_colour array. --- diff --git a/src/output/charts/barchart.c b/src/output/charts/barchart.c index 7869d5d6..88a1d741 100644 --- a/src/output/charts/barchart.c +++ b/src/output/charts/barchart.c @@ -148,7 +148,7 @@ draw_barchart(struct chart *ch, const char *title, { pl_savestate_r(ch->lp); - pl_fillcolorname_r(ch->lp,data_colour[sc]); + pl_fillcolorname_r(ch->lp,data_colour[sc % N_CHART_COLOURS]); switch ( opt ) { diff --git a/src/output/charts/piechart.c b/src/output/charts/piechart.c index c4dc0e67..4eeb10ca 100644 --- a/src/output/charts/piechart.c +++ b/src/output/charts/piechart.c @@ -96,7 +96,7 @@ piechart_plot(const char *title, const struct slice *slices, int n_slices) draw_segment(ch, centre_x, centre_y, radius, angle, segment_angle, - data_colour[i]); + data_colour[i % N_CHART_COLOURS]); /* Now add the labels */ if ( label_x < centre_x ) diff --git a/src/output/charts/plot-chart.c b/src/output/charts/plot-chart.c index 88aa58b0..3b4f1b37 100644 --- a/src/output/charts/plot-chart.c +++ b/src/output/charts/plot-chart.c @@ -38,17 +38,18 @@ #include "xalloc.h" -const char *const data_colour[] = { - "brown", - "red", - "orange", - "yellow", - "green", - "blue", - "violet", - "grey", - "pink" -}; +const char *const data_colour[N_CHART_COLOURS] = + { + "brown", + "red", + "orange", + "yellow", + "green", + "blue", + "violet", + "grey", + "pink" + }; diff --git a/src/output/charts/plot-chart.h b/src/output/charts/plot-chart.h index dae1cc07..4a1dc105 100644 --- a/src/output/charts/plot-chart.h +++ b/src/output/charts/plot-chart.h @@ -35,13 +35,14 @@ #ifndef PLOT_CHART_H #define PLOT_CHART_H - +#define N_CHART_COLOURS 9 extern const char *const data_colour[]; -enum tick_orientation { - TICK_ABSCISSA=0, - TICK_ORDINATE -}; +enum tick_orientation + { + TICK_ABSCISSA=0, + TICK_ORDINATE + }; /* Draw a tick mark at position diff --git a/tests/automake.mk b/tests/automake.mk index bfca93d4..b0039df4 100644 --- a/tests/automake.mk +++ b/tests/automake.mk @@ -121,6 +121,7 @@ dist_TESTS = \ tests/bugs/multipass.sh \ tests/bugs/overwrite-input-file.sh \ tests/bugs/overwrite-special-file.sh \ + tests/bugs/piechart.sh \ tests/bugs/random.sh \ tests/bugs/signals.sh \ tests/bugs/t-test-with-temp.sh \ diff --git a/tests/bugs/piechart.sh b/tests/bugs/piechart.sh new file mode 100755 index 00000000..657e5383 --- /dev/null +++ b/tests/bugs/piechart.sh @@ -0,0 +1,92 @@ +#!/bin/sh + +# This program tests for a bug which crashed pspp when a +# piechart with too many segments was requested. + + +TEMPDIR=/tmp/pspp-tst-$$ +TESTFILE=$TEMPDIR/`basename $0`.sps + +# ensure that top_builddir are absolute +if [ -z "$top_builddir" ] ; then top_builddir=. ; fi +if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi +top_builddir=`cd $top_builddir; pwd` +PSPP=$top_builddir/src/ui/terminal/pspp + +# ensure that top_srcdir is absolute +top_srcdir=`cd $top_srcdir; pwd` + +STAT_CONFIG_PATH=$top_srcdir/config +export STAT_CONFIG_PATH + + +cleanup() +{ + if [ x"$PSPP_TEST_NO_CLEANUP" != x ] ; then + echo "NOT cleaning $TEMPDIR" + return ; + fi + cd / + chmod u+w $TEMPDIR + rm -rf $TEMPDIR +} + + +fail() +{ + echo $activity + echo FAILED + cleanup; + exit 1; +} + + +no_result() +{ + echo $activity + echo NO RESULT; + cleanup; + exit 2; +} + +pass() +{ + cleanup; + exit 0; +} + +mkdir -p $TEMPDIR + +cd $TEMPDIR + +activity="create test syntax" +cat > $TESTFILE <