Skip to content

Commit

Permalink
Avoid passing non-literals to string formatting functions
Browse files Browse the repository at this point in the history
Having a string literal allows the compiler to check the arguments
match the format, so avoid passing non-literal whenever possible.
  • Loading branch information
b4n committed Jun 24, 2014
1 parent 135b60d commit 2490df9
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/filetypes.c
Expand Up @@ -87,21 +87,17 @@ enum TitleType
/* Save adding many translation strings if the filetype name doesn't need translating */
static gchar *filetype_make_title(const char *name, enum TitleType type)
{
const gchar *fmt = NULL;

g_return_val_if_fail(name != NULL, NULL);

switch (type)
{
case TITLE_SOURCE_FILE: fmt = _("%s source file"); break;
case TITLE_FILE: fmt = _("%s file"); break;
case TITLE_SCRIPT: fmt = _("%s script"); break;
case TITLE_DOCUMENT: fmt = _("%s document"); break;
case TITLE_SOURCE_FILE: return g_strdup_printf(_("%s source file"), name);
case TITLE_FILE: return g_strdup_printf(_("%s file"), name);
case TITLE_SCRIPT: return g_strdup_printf(_("%s script"), name);
case TITLE_DOCUMENT: return g_strdup_printf(_("%s document"), name);
case TITLE_NONE: /* fall through */
default: fmt = "%s"; break;
default: return g_strdup(name);
}

return g_strdup_printf(fmt, name);
}


Expand Down

0 comments on commit 2490df9

Please sign in to comment.