From ddf82a25761ed6aae17e478ab5d3096275b32b35 Mon Sep 17 00:00:00 2001 From: Ryan Lortie Date: Sun, 8 Dec 2013 14:22:51 -0500 Subject: [PATCH] [PATCH] Fix trivial non literal format uses Based on a patch from Henrique Dante de Almeida . https://bugzilla.gnome.org/show_bug.cgi?id=691608 --- gio/gcontenttype.c | 16 ++++++---------- gio/gthreadedresolver.c | 32 ++++++++++++-------------------- glib/tests/test-printf.c | 3 +++ 3 files changed, 21 insertions(+), 30 deletions(-) diff --git a/gio/gcontenttype.c b/gio/gcontenttype.c index 055df150a..a4ecde2d7 100644 --- a/gio/gcontenttype.c +++ b/gio/gcontenttype.c @@ -408,30 +408,26 @@ g_content_type_get_icon_internal (const gchar *type, char *icon_names[3]; int n = 0; GIcon *themed_icon; - const char *file_template; const char *xdg_icon; + const char *suffix; g_return_val_if_fail (type != NULL, NULL); if (symbolic) - { - file_template = "%s-symbolic"; - } + suffix = "-symbolic"; else - { - file_template = "%s"; - } + suffix = ""; G_LOCK (gio_xdgmime); xdg_icon = xdg_mime_get_icon (type); G_UNLOCK (gio_xdgmime); if (xdg_icon != NULL) - xdg_mimetype_icon = g_strdup_printf (file_template, xdg_icon); + xdg_mimetype_icon = g_strconcat (xdg_icon, suffix, NULL); if (xdg_mimetype_icon) icon_names[n++] = xdg_mimetype_icon; - mimetype_icon = g_strdup_printf (file_template, type); + mimetype_icon = g_strconcat (type, suffix, NULL); while ((q = strchr (mimetype_icon, '/')) != NULL) *q = '-'; @@ -439,7 +435,7 @@ g_content_type_get_icon_internal (const gchar *type, xdg_mimetype_generic_icon = g_content_type_get_generic_icon_name (type); if (xdg_mimetype_generic_icon) - generic_mimetype_icon = g_strdup_printf (file_template, xdg_mimetype_generic_icon); + generic_mimetype_icon = g_strconcat (xdg_mimetype_generic_icon, suffix, NULL); if (generic_mimetype_icon) icon_names[n++] = generic_mimetype_icon; diff --git a/gio/gthreadedresolver.c b/gio/gthreadedresolver.c index 1ffaf15c1..c00952941 100644 --- a/gio/gthreadedresolver.c +++ b/gio/gthreadedresolver.c @@ -527,26 +527,22 @@ g_resolver_records_from_res_query (const gchar *rrname, if (len <= 0) { - GResolverError errnum; - const gchar *format; - if (len == 0 || herr == HOST_NOT_FOUND || herr == NO_DATA) { - errnum = G_RESOLVER_ERROR_NOT_FOUND; - format = _("No DNS record of the requested type for '%s'"); + g_set_error (error, G_RESOLVER_ERROR, G_RESOLVER_ERROR_NOT_FOUND, + _("No DNS record of the requested type for '%s'"), rrname); } else if (herr == TRY_AGAIN) { - errnum = G_RESOLVER_ERROR_TEMPORARY_FAILURE; - format = _("Temporarily unable to resolve '%s'"); + g_set_error (error, G_RESOLVER_ERROR, G_RESOLVER_ERROR_TEMPORARY_FAILURE, + _("Temporarily unable to resolve '%s'"), rrname); } else { - errnum = G_RESOLVER_ERROR_INTERNAL; - format = _("Error resolving '%s'"); + g_set_error (error, G_RESOLVER_ERROR, G_RESOLVER_ERROR_INTERNAL, + _("Error resolving '%s'"), rrname); } - g_set_error (error, G_RESOLVER_ERROR, errnum, format, rrname); return NULL; } @@ -711,26 +707,22 @@ g_resolver_records_from_DnsQuery (const gchar *rrname, if (status != ERROR_SUCCESS) { - GResolverError errnum; - const gchar *format; - if (status == DNS_ERROR_RCODE_NAME_ERROR) { - errnum = G_RESOLVER_ERROR_NOT_FOUND; - format = _("No DNS record of the requested type for '%s'"); + g_set_error (error, G_RESOLVER_ERROR, G_RESOLVER_ERROR_NOT_FOUND, + _("No DNS record of the requested type for '%s'"), rrname); } else if (status == DNS_ERROR_RCODE_SERVER_FAILURE) { - errnum = G_RESOLVER_ERROR_TEMPORARY_FAILURE; - format = _("Temporarily unable to resolve '%s'"); + g_set_error (error, G_RESOLVER_ERROR, G_RESOLVER_ERROR_TEMPORARY_FAILURE, + _("Temporarily unable to resolve '%s'"), rrname); } else { - errnum = G_RESOLVER_ERROR_INTERNAL; - format = _("Error resolving '%s'"); + g_set_error (error, G_RESOLVER_ERROR, G_RESOLVER_ERROR_INTERNAL, + _("Error resolving '%s'"), rrname); } - g_set_error (error, G_RESOLVER_ERROR, errnum, format, rrname); return NULL; } diff --git a/glib/tests/test-printf.c b/glib/tests/test-printf.c index d845dfa7d..0dba0c0bc 100644 --- a/glib/tests/test-printf.c +++ b/glib/tests/test-printf.c @@ -188,6 +188,8 @@ test_d (void) * the "0" in "%-03d".) But we need to test that our printf gets * those rules right. So we fool gcc into not warning. */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat" fmt = "% +d"; res = g_snprintf (buf, 128, fmt, 5); g_assert_cmpint (res, ==, 2); @@ -197,6 +199,7 @@ test_d (void) res = g_snprintf (buf, 128, fmt, -5); g_assert_cmpint (res, ==, 3); g_assert_cmpstr (buf, ==, "-5 "); +#pragma GCC diagnostic pop } static void