syntax-string-source: Fix format string problems.
authorBen Pfaff <blp@cs.stanford.edu>
Fri, 17 Sep 2010 23:50:44 +0000 (16:50 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Fri, 24 Sep 2010 03:45:30 +0000 (20:45 -0700)
create_syntax_string_source() treated its argument as a printf-style format
string but wasn't annotated properly.  Most of the callers did not pass
string literals and were not escaped, so change it not to format its string
and add a new function create_syntax_format_source() with the previous
behavior.

src/language/syntax-string-source.c
src/language/syntax-string-source.h
src/ui/gui/psppire-data-window.c

index 405141cd50a7fd1734f387281b5b344d5a7e74f9..3860b8987cc805e6226fddbcb1cdcd8b01f4475f 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPPIRE - a graphical interface for PSPP.
-   Copyright (C) 2007, 2009 Free Software Foundation, Inc.
+   Copyright (C) 2007, 2009, 2010 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
@@ -100,21 +100,13 @@ read_single_line (struct getl_interface *i,
   return true;
 }
 
-struct getl_interface *
-create_syntax_string_source (const char *format, ...)
+static struct syntax_string_source *
+create_syntax_string_source__ (void)
 {
-  va_list args;
-
   struct syntax_string_source *sss = xzalloc (sizeof *sss);
 
   sss->posn = 0;
 
-  ds_init_empty (&sss->buffer);
-
-  va_start (args, format);
-  ds_put_vformat (&sss->buffer, format, args);
-  va_end (args);
-
   sss->parent.interactive = always_false;
   sss->parent.close = do_close;
   sss->parent.read = read_single_line;
@@ -122,6 +114,30 @@ create_syntax_string_source (const char *format, ...)
   sss->parent.name = name;
   sss->parent.location = location;
 
+  return sss;
+}
+
+struct getl_interface *
+create_syntax_string_source (const char *s)
+{
+  struct syntax_string_source *sss = create_syntax_string_source__ ();
+  ds_init_cstr (&sss->buffer, s);
+  return &sss->parent;
+}
+
+struct getl_interface *
+create_syntax_format_source (const char *format, ...)
+{
+  struct syntax_string_source *sss;
+  va_list args;
+
+  sss = create_syntax_string_source__ ();
+
+  ds_init_empty (&sss->buffer);
+
+  va_start (args, format);
+  ds_put_vformat (&sss->buffer, format, args);
+  va_end (args);
 
   return &sss->parent;
 }
index 42d1f4e98db72202c28aee4d26acbba6f8d763b0..d2e1a9ba82c52c781288d491d6d7e1f9c0598739 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPPIRE - a graphical interface for PSPP.
-   Copyright (C) 2007 Free Software Foundation, Inc.
+   Copyright (C) 2007, 2010 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
 #ifndef SYNTAX_STRING_SOURCE_H
 #define SYNTAX_STRING_SOURCE_H
 
+#include "libpspp/compiler.h"
+
 struct getl_interface;
 
 struct syntax_string_source;
 
-struct getl_interface * create_syntax_string_source (const char *fmt, ...);
+struct getl_interface *create_syntax_string_source (const char *);
+struct getl_interface *create_syntax_format_source (const char *, ...)
+  PRINTF_FORMAT (1, 2);
 
 const char * syntax_string_source_get_syntax (const struct syntax_string_source *s);
 
index dd87f53f7b92ac47bf5c7026049005d26e5419f8..63ad9fe1bdc0457644ff5c9865a7c9c7f3acab1e 100644 (file)
@@ -365,7 +365,7 @@ load_file (PsppireWindow *de, const gchar *file_name)
 
   g_free (native_file_name);
 
-  sss = create_syntax_string_source ("GET FILE=%s.",
+  sss = create_syntax_format_source ("GET FILE=%s.",
                                     ds_cstr (&filename));
 
   ds_destroy (&filename);
@@ -530,12 +530,12 @@ save_file (PsppireWindow *w)
 
   if ( de->save_as_portable )
     {
-      sss = create_syntax_string_source ("EXPORT OUTFILE=%s.",
+      sss = create_syntax_format_source ("EXPORT OUTFILE=%s.",
                                         ds_cstr (&filename));
     }
   else
     {
-      sss = create_syntax_string_source ("SAVE OUTFILE=%s.",
+      sss = create_syntax_format_source ("SAVE OUTFILE=%s.",
                                         ds_cstr (&filename));
     }
 
@@ -589,7 +589,7 @@ sysfile_info (PsppireDataWindow *de)
 
       g_free (native_file_name);
 
-      sss = create_syntax_string_source ("SYSFILE INFO %s.",
+      sss = create_syntax_format_source ("SYSFILE INFO %s.",
                                         ds_cstr (&filename));
       execute_syntax (sss);
     }