[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[pre-lexer 04/21] syntax-string-source: Fix format string problems.
From: |
Ben Pfaff |
Subject: |
[pre-lexer 04/21] syntax-string-source: Fix format string problems. |
Date: |
Thu, 23 Sep 2010 21:20:40 -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 | 38 ++++++++++++++++++++++++----------
src/language/syntax-string-source.h | 8 +++++-
src/ui/gui/psppire-data-window.c | 8 +++---
3 files changed, 37 insertions(+), 17 deletions(-)
diff --git a/src/language/syntax-string-source.c
b/src/language/syntax-string-source.c
index 405141c..3860b89 100644
--- a/src/language/syntax-string-source.c
+++ b/src/language/syntax-string-source.c
@@ -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;
}
diff --git a/src/language/syntax-string-source.h
b/src/language/syntax-string-source.h
index 42d1f4e..d2e1a9b 100644
--- a/src/language/syntax-string-source.h
+++ b/src/language/syntax-string-source.h
@@ -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
@@ -17,11 +17,15 @@
#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);
diff --git a/src/ui/gui/psppire-data-window.c b/src/ui/gui/psppire-data-window.c
index dd87f53..63ad9fe 100644
--- a/src/ui/gui/psppire-data-window.c
+++ b/src/ui/gui/psppire-data-window.c
@@ -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);
}
--
1.7.1
- [pre-lexer 00/21] preparation for work on lexer, Ben Pfaff, 2010/09/24
- [pre-lexer 01/21] str: Make ss_alloc_substring() allocate null-terminated strings., Ben Pfaff, 2010/09/24
- [pre-lexer 13/21] command: Remove superfluous trailing spaces from command names., Ben Pfaff, 2010/09/24
- [pre-lexer 19/21] data-in: Rewrite logic for recoding input, and get rid of src_enc member., Ben Pfaff, 2010/09/24
- [pre-lexer 03/21] i18n: New function recode_substring_pool()., Ben Pfaff, 2010/09/24
- [pre-lexer 11/21] lexer: Use lex_is_string() more consistently., Ben Pfaff, 2010/09/24
- [pre-lexer 04/21] syntax-string-source: Fix format string problems.,
Ben Pfaff <=
- [pre-lexer 08/21] Make translation easier., Ben Pfaff, 2010/09/24
- [pre-lexer 14/21] command: Add specific DATASET unimplemented commands., Ben Pfaff, 2010/09/24
- [pre-lexer 12/21] command: Remove INSERT from list of unimplemented commands., Ben Pfaff, 2010/09/24
- [pre-lexer 20/21] data-in: Make data_in() parameters more uniform., Ben Pfaff, 2010/09/24
- [pre-lexer 02/21] i18n: Use UTF8 macro instead of "UTF8" literal string., Ben Pfaff, 2010/09/24
- [pre-lexer 09/21] lexer: Improve translatability of lex_error()., Ben Pfaff, 2010/09/24
- [pre-lexer 15/21] message: Consistently initialize locator; use 0 for "no line number"., Ben Pfaff, 2010/09/24
- [pre-lexer 06/21] AGGREGATE: Simplify code., Ben Pfaff, 2010/09/24
- [pre-lexer 17/21] calendar: Use sensible error reporting in calendar_gregorian_to_offset()., Ben Pfaff, 2010/09/24
- [pre-lexer 16/21] message: Add column range to struct msg_locator., Ben Pfaff, 2010/09/24