From: Ben Pfaff Date: Thu, 2 Jul 2009 03:56:17 +0000 (-0700) Subject: chart: Fix format string issues in draw_tick callers. X-Git-Tag: v0.7.3~11 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9bc7fd4e5d03e4960960d9b16339a680d6f9ae06;p=pspp-builds.git chart: Fix format string issues in draw_tick callers. The 'label' argument to draw_tick is used as a printf-type format string, so callers must pass "%s" to safely use an arbitrary string as a label. Also, hist_draw_bar was doing its own snprintf, but this commit changes it to take advantage of that provided by draw_tick. --- diff --git a/src/output/charts/barchart.c b/src/output/charts/barchart.c index 96cd07fb..f3b10011 100644 --- a/src/output/charts/barchart.c +++ b/src/output/charts/barchart.c @@ -141,7 +141,7 @@ draw_barchart(struct chart *ch, const char *title, pl_savestate_r(ch->lp); - draw_tick (ch, TICK_ABSCISSA, x + (interval_size/2 ), + draw_tick (ch, TICK_ABSCISSA, x + (interval_size/2 ), "%s", cat_labels[i]); for(sc = 0 ; sc < SUB_CATAGORIES ; ++sc ) diff --git a/src/output/charts/box-whisker.c b/src/output/charts/box-whisker.c index c3641580..33c445b0 100644 --- a/src/output/charts/box-whisker.c +++ b/src/output/charts/box-whisker.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2004, 2008 Free Software Foundation, Inc. + Copyright (C) 2004, 2008, 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 @@ -147,7 +147,7 @@ boxplot_draw_boxplot (struct chart *ch, } /* Draw tick mark on x axis */ - draw_tick(ch, TICK_ABSCISSA, box_centre - ch->data_left, name); + draw_tick(ch, TICK_ABSCISSA, box_centre - ch->data_left, "%s", name); pl_restorestate_r(ch->lp); } diff --git a/src/output/charts/plot-chart.h b/src/output/charts/plot-chart.h index f29b4a35..9a4df520 100644 --- a/src/output/charts/plot-chart.h +++ b/src/output/charts/plot-chart.h @@ -52,7 +52,8 @@ enum tick_orientation void draw_tick(struct chart *chart, enum tick_orientation orientation, double position, - const char *label, ...); + const char *label, ...) + PRINTF_FORMAT (4, 5); /* Write the title on a chart*/ diff --git a/src/output/charts/plot-hist.c b/src/output/charts/plot-hist.c index abe29088..b90d57ac 100644 --- a/src/output/charts/plot-hist.c +++ b/src/output/charts/plot-hist.c @@ -112,12 +112,8 @@ hist_draw_bar (struct chart *ch, const struct histogram *hist, int bar) pl_restorestate_r (ch->lp); - { - char buf[5]; - snprintf (buf,5,"%g", (upper + lower) / 2.0); - draw_tick (ch, TICK_ABSCISSA, - x_pos + width / 2.0, buf); - } + draw_tick (ch, TICK_ABSCISSA, + x_pos + width / 2.0, "%g", (upper + lower) / 2.0); } }