From 44dab63eeb3b50a9939d58005e63b2bfae0f846f Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 1 Jul 2009 20:56:17 -0700 Subject: [PATCH] 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. --- src/output/charts/barchart.c | 2 +- src/output/charts/box-whisker.c | 4 ++-- src/output/charts/plot-chart.h | 3 ++- src/output/charts/plot-hist.c | 10 +++------- 4 files changed, 8 insertions(+), 11 deletions(-) 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 d4a5ccab..8bcad494 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 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 @@ -203,7 +203,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 0f183208..b567370c 100644 --- a/src/output/charts/plot-hist.c +++ b/src/output/charts/plot-hist.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 @@ -98,12 +98,8 @@ hist_draw_bar(struct chart *ch, const gsl_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); } } -- 2.30.2