From f9bad53e96e50abef183e84ccf6964dba67b3ca5 Mon Sep 17 00:00:00 2001
From: Ben Pfaff <blp@gnu.org>
Date: Wed, 1 Jul 2009 20:50:33 -0700
Subject: [PATCH 1/2] 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 febb60f..4254d4f 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 88a1d74..96cd07f 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 4eeb10c..aa52f99 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 4a1dc10..f29b4a3 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 <math/chart-geometry.h>
 #include <output/chart.h>
 
+#include <libpspp/compiler.h>
 #include <libpspp/str.h>
 #include <output/manager.h>
 #include <output/output.h>
@@ -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 */
-- 
1.6.3.1

