From f9bad53e96e50abef183e84ccf6964dba67b3ca5 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 1 Jul 2009 20:50:33 -0700 Subject: [PATCH] chart: Fix format string issues in chart_write_title callers. The 'title' argument to chart_write_title is used as a printf-type format string, so callers must pass "%s" to safely use an arbitrary string as a title. --- src/language/stats/examine.q | 2 +- src/output/charts/barchart.c | 4 ++-- src/output/charts/piechart.c | 2 +- src/output/charts/plot-chart.h | 6 ++++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/language/stats/examine.q b/src/language/stats/examine.q index febb60fe..4254d4fb 100644 --- a/src/language/stats/examine.q +++ b/src/language/stats/examine.q @@ -1800,7 +1800,7 @@ box_plot_variables (const struct factor *fctr, ds_init_empty (&str); factor_to_string (fctr, *fs, 0, &str ); - chart_write_title (ch, ds_cstr (&str)); + chart_write_title (ch, "%s", ds_cstr (&str)); for ( i = 0 ; i < n_vars ; ++i ) { diff --git a/src/output/charts/barchart.c b/src/output/charts/barchart.c index 88a1d741..96cd07fb 100644 --- a/src/output/charts/barchart.c +++ b/src/output/charts/barchart.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 @@ -202,7 +202,7 @@ draw_barchart(struct chart *ch, const char *title, pl_restorestate_r(ch->lp); - chart_write_title(ch, title); + chart_write_title(ch, "%s", title); write_legend(ch); diff --git a/src/output/charts/piechart.c b/src/output/charts/piechart.c index 4eeb10ca..aa52f99e 100644 --- a/src/output/charts/piechart.c +++ b/src/output/charts/piechart.c @@ -74,7 +74,7 @@ piechart_plot(const char *title, const struct slice *slices, int n_slices) ); - chart_write_title(ch, title); + chart_write_title(ch, "%s", title); for (i = 0 ; i < n_slices ; ++i ) total_magnetude += slices[i].magnetude; diff --git a/src/output/charts/plot-chart.h b/src/output/charts/plot-chart.h index 4a1dc105..f29b4a35 100644 --- a/src/output/charts/plot-chart.h +++ b/src/output/charts/plot-chart.h @@ -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 @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -55,7 +56,8 @@ void draw_tick(struct chart *chart, /* Write the title on a chart*/ -void chart_write_title(struct chart *chart, const char *title, ...); +void chart_write_title(struct chart *chart, const char *title, ...) + PRINTF_FORMAT (2, 3); /* Set the scale for the abscissa */ -- 2.30.2