Commit 466bf2f6 authored by Thomas Haller's avatar Thomas Haller

build: avoid compiler warnings about non-constant format strings (-Wformat-nonliteral)

parent b1e267cd
......@@ -53,6 +53,8 @@
#define PROMPT_IP_TUNNEL_MODE _("Tunnel mode: ")
#define PROMPT_MACVLAN_MODE _("MACVLAN mode: ")
#define BASE_PROMPT "nmcli> "
/* Available fields for 'connection show' */
static NmcOutputField nmc_fields_con_show[] = {
{"NAME", N_("NAME")}, /* 0 */
......@@ -9006,7 +9008,6 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
gboolean cmd_loop = TRUE;
char *cmd_arg = NULL;
char *cmd_arg_s, *cmd_arg_p, *cmd_arg_v;
const char *BASE_PROMPT = "nmcli> ";
const NameItem *valid_settings_main = NULL;
const NameItem *valid_settings_slave = NULL;
char *valid_settings_str = NULL;
......
......@@ -2498,13 +2498,16 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv)
show_access_point_info (device, nmc);
}
} else {
const char *err_msg;
if ( nm_device_get_device_type (device) == NM_DEVICE_TYPE_GENERIC
&& g_strcmp0 (nm_device_get_type_description (device), "wifi") == 0)
err_msg = _("Error: Device '%s' was not recognized as a Wi-Fi device, check NetworkManager Wi-Fi plugin.");
else
err_msg = _("Error: Device '%s' is not a Wi-Fi device.");
g_string_printf (nmc->return_text, err_msg, ifname);
&& g_strcmp0 (nm_device_get_type_description (device), "wifi") == 0) {
g_string_printf (nmc->return_text,
_("Error: Device '%s' was not recognized as a Wi-Fi device, check NetworkManager Wi-Fi plugin."),
ifname);
} else {
g_string_printf (nmc->return_text,
_("Error: Device '%s' is not a Wi-Fi device."),
ifname);
}
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
goto error;
}
......
......@@ -893,20 +893,13 @@ static void
networkmanager_running (NMClient *client, GParamSpec *param, NmCli *nmc)
{
gboolean running;
NmcTermColor color;
const char *message;
char *str;
running = nm_client_get_nm_running (client);
if (running) {
color = NMC_TERM_COLOR_GREEN;
message = _("NetworkManager has started");
} else {
color = NMC_TERM_COLOR_RED;
message = _("NetworkManager has stopped");
}
str = nmc_colorize (nmc, color, NMC_TERM_FORMAT_NORMAL, message);
str = nmc_colorize (nmc,
running ? NMC_TERM_COLOR_GREEN : NMC_TERM_COLOR_RED,
NMC_TERM_FORMAT_NORMAL,
running ? _("NetworkManager has started") : _("NetworkManager has stopped"));
g_print ("%s\n", str);
g_free (str);
}
......
......@@ -1005,7 +1005,7 @@ colorize_string (NmCli *nmc,
if ( use_colors (nmc)
&& (color != NMC_TERM_COLOR_NORMAL || color_fmt != NMC_TERM_FORMAT_NORMAL)) {
out = nmc_colorize (nmc, color, color_fmt, str);
out = nmc_colorize (nmc, color, color_fmt, "%s", str);
*dealloc = TRUE;
} else {
out = (char *) str;
......
......@@ -74,7 +74,7 @@ void nmc_terminal_show_progress (const char *str);
const char *nmc_term_color_sequence (NmcTermColor color);
const char *nmc_term_format_sequence (NmcTermFormat format);
NmcTermColor nmc_term_color_parse_string (const char *str, GError **error);
char *nmc_colorize (NmCli *nmc, NmcTermColor color, NmcTermFormat format, const char * fmt, ...);
char *nmc_colorize (NmCli *nmc, NmcTermColor color, NmcTermFormat format, const char * fmt, ...) __attribute__((__format__ (__printf__, 4, 5)));
void nmc_filter_out_colors_inplace (char *str);
char *nmc_filter_out_colors (const char *str);
char *nmc_get_user_input (const char *ask_str);
......
......@@ -41,11 +41,11 @@ char *nmt_newt_locale_from_utf8 (const char *str_utf8);
int nmt_newt_text_width (const char *str);
void nmt_newt_message_dialog (const char *message,
...);
...) __attribute__((__format__ (__printf__, 1, 2)));
int nmt_newt_choice_dialog (const char *button1,
const char *button2,
const char *message,
...);
...) __attribute__((__format__ (__printf__, 3, 4)));
char *nmt_newt_edit_string (const char *data);
......
......@@ -252,6 +252,16 @@ nm_editor_utils_get_connection_type_list (void)
return list;
}
static void
_assert_format_int (const char *format)
{
g_assert (format);
format = strchr (format, '%');
g_assert (format);
g_assert (!strchr (format, '%'));
g_assert (format[1] == 'd');
}
static char *
get_available_connection_name (const char *format,
NMClient *client)
......@@ -261,6 +271,10 @@ get_available_connection_name (const char *format,
char *cname = NULL;
int i = 0;
#if NM_MORE_ASSERTS
_assert_format_int (format);
#endif
conns = nm_client_get_connections (client);
for (i = 0; i < conns->len; i++) {
const char *id;
......@@ -275,7 +289,9 @@ get_available_connection_name (const char *format,
char *temp;
gboolean found = FALSE;
NM_PRAGMA_WARNING_DISABLE("-Wformat-nonliteral")
temp = g_strdup_printf (format, i);
NM_PRAGMA_WARNING_REENABLE
for (iter = names; iter; iter = g_slist_next (iter)) {
if (!strcmp (iter->data, temp)) {
found = TRUE;
......
......@@ -6931,19 +6931,12 @@ share_init (void)
return TRUE;
}
static void
add_share_rule (NMActRequest *req, const char *table, const char *fmt, ...)
{
va_list args;
char *cmd;
va_start (args, fmt);
cmd = g_strdup_vprintf (fmt, args);
va_end (args);
nm_act_request_add_share_rule (req, table, cmd);
g_free (cmd);
}
#define add_share_rule(req, table, ...) \
G_STMT_START { \
char *_cmd = g_strdup_printf (__VA_ARGS__); \
nm_act_request_add_share_rule (req, table, _cmd); \
g_free (_cmd); \
} G_STMT_END
static gboolean
start_sharing (NMDevice *self, NMIP4Config *config)
......
......@@ -242,6 +242,7 @@ nm_main_utils_early_setup (const char *progname,
textdomain (GETTEXT_PACKAGE);
for (i = 0; options[i].long_name; i++) {
NM_PRAGMA_WARNING_DISABLE("-Wformat-nonliteral")
if (!strcmp (options[i].long_name, "log-level")) {
opt_fmt_log_level = options[i].description;
opt_loc_log_level = &options[i].description;
......@@ -251,6 +252,7 @@ nm_main_utils_early_setup (const char *progname,
opt_loc_log_domains = &options[i].description;
options[i].description = g_strdup_printf (options[i].description, nm_logging_all_domains_to_string ());
}
NM_PRAGMA_WARNING_REENABLE
}
/* Parse options */
......
......@@ -571,7 +571,9 @@ _create_export_path (NMExportedObjectClass *klass)
g_hash_table_insert (prefix_counters, g_strdup (class_export_path), counter);
}
NM_PRAGMA_WARNING_DISABLE("-Wformat-nonliteral")
return g_strdup_printf (class_export_path, (*counter)++);
NM_PRAGMA_WARNING_REENABLE
}
return g_strdup (class_export_path);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment