X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Foutput%2Fcharts%2Fboxplot.c;h=3261d02eba685c252018fcfdafe262376f141f33;hb=010a024889199741ca697f95a34f8635f4ab2917;hp=deabc1fa6e8f059c026c5c079b6e4a60f43b0b5a;hpb=fe8dc2171009e90d2335f159d05f7e6660e24780;p=pspp diff --git a/src/output/charts/boxplot.c b/src/output/charts/boxplot.c index deabc1fa6e..3261d02eba 100644 --- a/src/output/charts/boxplot.c +++ b/src/output/charts/boxplot.c @@ -20,13 +20,15 @@ #include "output/charts/boxplot.h" #include "math/box-whisker.h" -#include "output/chart-item-provider.h" +#include "output/chart-provider.h" 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); + chart_init (&boxplot->chart, &boxplot_class, title); boxplot->y_min = y_min; boxplot->y_max = y_max; boxplot->boxes = NULL; @@ -38,6 +40,13 @@ void boxplot_add_box (struct boxplot *boxplot, struct box_whisker *bw, const char *label) { + if (boxplot == NULL) + { + struct statistic *statistic = &bw->parent.parent; + statistic->destroy (statistic); + return; + } + struct boxplot_box *box; if (boxplot->n_boxes >= boxplot->boxes_allocated) boxplot->boxes = x2nrealloc (boxplot->boxes, &boxplot->boxes_allocated, @@ -48,9 +57,12 @@ boxplot_add_box (struct boxplot *boxplot, } static void -boxplot_chart_destroy (struct chart_item *chart_item) +boxplot_chart_destroy (struct chart *chart) { - struct boxplot *boxplot = to_boxplot (chart_item); + struct boxplot *boxplot = to_boxplot (chart); + if (boxplot == NULL) + return; + size_t i; for (i = 0; i < boxplot->n_boxes; i++) @@ -64,7 +76,7 @@ boxplot_chart_destroy (struct chart_item *chart_item) free (boxplot); } -const struct chart_item_class boxplot_class = +const struct chart_class boxplot_class = { boxplot_chart_destroy };