Bug 555311 – format not a string literal and no format arguments

svn path=/trunk/; revision=7597
This commit is contained in:
Christian Persch 2008-10-13 12:43:37 +00:00
parent 6eb38fb4db
commit 630f89fb1a
4 changed files with 77 additions and 64 deletions

View File

@ -1,3 +1,10 @@
2008-10-13 Christian Persch <chpe@gnome.org>
Bug 555311 format not a string literal and no format arguments
* glib/gmarkup.c:
* glib/gshell.c: Use literal errors where appropriate.
2008-10-10 Behdad Esfahbod <behdad@gnome.org> 2008-10-10 Behdad Esfahbod <behdad@gnome.org>
Bug 551355 [PATCH] Make glib build with libtool 2.2 Bug 551355 [PATCH] Make glib build with libtool 2.2

View File

@ -609,8 +609,7 @@ run_in_thread (GIOSchedulerJob *job,
g_simple_async_result_set_error (simple, g_simple_async_result_set_error (simple,
G_IO_ERROR, G_IO_ERROR,
G_IO_ERROR_CANCELLED, G_IO_ERROR_CANCELLED,
"%s", "%s", _("Operation was cancelled"));
_("Operation was cancelled"));
else else
data->func (simple, data->func (simple,
simple->source_object, simple->source_object,

View File

@ -241,6 +241,26 @@ static void set_error (GMarkupParseContext *context,
const gchar *format, const gchar *format,
...) G_GNUC_PRINTF (4, 5); ...) G_GNUC_PRINTF (4, 5);
static void
set_error_literal (GMarkupParseContext *context,
GError **error,
GMarkupError code,
const gchar *message)
{
GError *tmp_error;
tmp_error = g_error_new_literal (G_MARKUP_ERROR, code, message);
g_prefix_error (&tmp_error,
_("Error on line %d char %d: "),
context->line_number,
context->char_number);
mark_error (context, tmp_error);
g_propagate_error (error, tmp_error);
}
static void static void
set_error (GMarkupParseContext *context, set_error (GMarkupParseContext *context,
GError **error, GError **error,
@ -248,7 +268,6 @@ set_error (GMarkupParseContext *context,
const gchar *format, const gchar *format,
...) ...)
{ {
GError *tmp_error;
gchar *s; gchar *s;
gchar *s_valid; gchar *s_valid;
va_list args; va_list args;
@ -260,19 +279,10 @@ set_error (GMarkupParseContext *context,
/* Make sure that the GError message is valid UTF-8 even if it is /* Make sure that the GError message is valid UTF-8 even if it is
* complaining about invalid UTF-8 in the markup: */ * complaining about invalid UTF-8 in the markup: */
s_valid = _g_utf8_make_valid (s); s_valid = _g_utf8_make_valid (s);
tmp_error = g_error_new_literal (G_MARKUP_ERROR, code, s_valid); set_error_literal (context, error, code, s);
g_free (s); g_free (s);
g_free (s_valid); g_free (s_valid);
g_prefix_error (&tmp_error,
_("Error on line %d char %d: "),
context->line_number,
context->char_number);
mark_error (context, tmp_error);
g_propagate_error (error, tmp_error);
} }
static void static void
@ -1047,11 +1057,10 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
/* The leftover char portion is too big to be /* The leftover char portion is too big to be
* a UTF-8 character * a UTF-8 character
*/ */
set_error (context, set_error_literal (context,
error, error,
G_MARKUP_ERROR_BAD_UTF8, G_MARKUP_ERROR_BAD_UTF8,
"%s", _("Invalid UTF-8 encoded text - overlong sequence"));
_("Invalid UTF-8 encoded text - overlong sequence"));
} }
goto finished; goto finished;
@ -1076,11 +1085,10 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
*/ */
if ((*context->current_text & 0xc0) == 0x80) /* not a char start */ if ((*context->current_text & 0xc0) == 0x80) /* not a char start */
{ {
set_error (context, set_error_literal (context,
error, error,
G_MARKUP_ERROR_BAD_UTF8, G_MARKUP_ERROR_BAD_UTF8,
"%s", _("Invalid UTF-8 encoded text - not a start char"));
_("Invalid UTF-8 encoded text - not a start char"));
goto finished; goto finished;
} }
@ -1154,11 +1162,10 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
} }
else else
{ {
set_error (context, set_error_literal (context,
error, error,
G_MARKUP_ERROR_PARSE, G_MARKUP_ERROR_PARSE,
"%s", _("Document must begin with an element (e.g. <book>)"));
_("Document must begin with an element (e.g. <book>)"));
} }
} }
break; break;
@ -1847,8 +1854,8 @@ g_markup_parse_context_end_parse (GMarkupParseContext *context,
if (context->document_empty) if (context->document_empty)
{ {
set_error (context, error, G_MARKUP_ERROR_EMPTY, "%s", set_error_literal (context, error, G_MARKUP_ERROR_EMPTY,
_("Document was empty or contained only whitespace")); _("Document was empty or contained only whitespace"));
return FALSE; return FALSE;
} }
@ -1861,8 +1868,8 @@ g_markup_parse_context_end_parse (GMarkupParseContext *context,
break; break;
case STATE_AFTER_OPEN_ANGLE: case STATE_AFTER_OPEN_ANGLE:
set_error (context, error, G_MARKUP_ERROR_PARSE, "%s", set_error_literal (context, error, G_MARKUP_ERROR_PARSE,
_("Document ended unexpectedly just after an open angle bracket '<'")); _("Document ended unexpectedly just after an open angle bracket '<'"));
break; break;
case STATE_AFTER_CLOSE_ANGLE: case STATE_AFTER_CLOSE_ANGLE:
@ -1883,33 +1890,33 @@ g_markup_parse_context_end_parse (GMarkupParseContext *context,
break; break;
case STATE_INSIDE_OPEN_TAG_NAME: case STATE_INSIDE_OPEN_TAG_NAME:
set_error (context, error, G_MARKUP_ERROR_PARSE, "%s", set_error_literal (context, error, G_MARKUP_ERROR_PARSE,
_("Document ended unexpectedly inside an element name")); _("Document ended unexpectedly inside an element name"));
break; break;
case STATE_INSIDE_ATTRIBUTE_NAME: case STATE_INSIDE_ATTRIBUTE_NAME:
case STATE_AFTER_ATTRIBUTE_NAME: case STATE_AFTER_ATTRIBUTE_NAME:
set_error (context, error, G_MARKUP_ERROR_PARSE, "%s", set_error_literal (context, error, G_MARKUP_ERROR_PARSE,
_("Document ended unexpectedly inside an attribute name")); _("Document ended unexpectedly inside an attribute name"));
break; break;
case STATE_BETWEEN_ATTRIBUTES: case STATE_BETWEEN_ATTRIBUTES:
set_error (context, error, G_MARKUP_ERROR_PARSE, "%s", set_error_literal (context, error, G_MARKUP_ERROR_PARSE,
_("Document ended unexpectedly inside an element-opening " _("Document ended unexpectedly inside an element-opening "
"tag.")); "tag."));
break; break;
case STATE_AFTER_ATTRIBUTE_EQUALS_SIGN: case STATE_AFTER_ATTRIBUTE_EQUALS_SIGN:
set_error (context, error, G_MARKUP_ERROR_PARSE, "%s", set_error_literal (context, error, G_MARKUP_ERROR_PARSE,
_("Document ended unexpectedly after the equals sign " _("Document ended unexpectedly after the equals sign "
"following an attribute name; no attribute value")); "following an attribute name; no attribute value"));
break; break;
case STATE_INSIDE_ATTRIBUTE_VALUE_SQ: case STATE_INSIDE_ATTRIBUTE_VALUE_SQ:
case STATE_INSIDE_ATTRIBUTE_VALUE_DQ: case STATE_INSIDE_ATTRIBUTE_VALUE_DQ:
set_error (context, error, G_MARKUP_ERROR_PARSE, "%s", set_error_literal (context, error, G_MARKUP_ERROR_PARSE,
_("Document ended unexpectedly while inside an attribute " _("Document ended unexpectedly while inside an attribute "
"value")); "value"));
break; break;
case STATE_INSIDE_TEXT: case STATE_INSIDE_TEXT:
@ -1929,9 +1936,9 @@ g_markup_parse_context_end_parse (GMarkupParseContext *context,
break; break;
case STATE_INSIDE_PASSTHROUGH: case STATE_INSIDE_PASSTHROUGH:
set_error (context, error, G_MARKUP_ERROR_PARSE, "%s", set_error_literal (context, error, G_MARKUP_ERROR_PARSE,
_("Document ended unexpectedly inside a comment or " _("Document ended unexpectedly inside a comment or "
"processing instruction")); "processing instruction"));
break; break;
case STATE_ERROR: case STATE_ERROR:

View File

@ -64,10 +64,10 @@ unquote_string_inplace (gchar* str, gchar** end, GError** err)
if (!(*s == '"' || *s == '\'')) if (!(*s == '"' || *s == '\''))
{ {
if (err) g_set_error_literal (err,
*err = g_error_new_literal (G_SHELL_ERROR, G_SHELL_ERROR,
G_SHELL_ERROR_BAD_QUOTING, G_SHELL_ERROR_BAD_QUOTING,
_("Quoted text doesn't begin with a quotation mark")); _("Quoted text doesn't begin with a quotation mark"));
*end = str; *end = str;
return FALSE; return FALSE;
} }
@ -154,10 +154,10 @@ unquote_string_inplace (gchar* str, gchar** end, GError** err)
*dest = '\0'; *dest = '\0';
if (err) g_set_error_literal (err,
*err = g_error_new_literal (G_SHELL_ERROR, G_SHELL_ERROR,
G_SHELL_ERROR_BAD_QUOTING, G_SHELL_ERROR_BAD_QUOTING,
_("Unmatched quotation mark in command line or other shell-quoted text")); _("Unmatched quotation mark in command line or other shell-quoted text"));
*end = s; *end = s;
return FALSE; return FALSE;
} }