summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-06-06 14:53:32 +0200
committerThomas Haller <thaller@redhat.com>2016-06-06 14:53:45 +0200
commit852a8968df126001c8b626bc5f33e678e6f13632 (patch)
tree26040f551123e9683a9df5300c9a1fe265e725ec
parent0c197cce44a01ce8f1628e157768d8ea94ec4ed2 (diff)
parent9b003381815b50ce762fa9eadeebc786b955fbe5 (diff)
downloadnetwork-manager-applet-852a8968df126001c8b626bc5f33e678e6f13632.tar.gz
build: merge branch 'build-fix-compiler-warnings'
https://bugzilla.gnome.org/show_bug.cgi?id=767208
-rw-r--r--m4/compiler_options.m4 (renamed from m4/compiler_warnings.m4)55
-rw-r--r--shared/nm-macros-internal.h35
-rw-r--r--src/applet-dialogs.c5
-rw-r--r--src/applet-dialogs.h2
-rw-r--r--src/applet.c2
-rw-r--r--src/connection-editor/ce-page.c2
-rw-r--r--src/connection-editor/nm-connection-editor.c14
-rw-r--r--src/connection-editor/nm-connection-editor.h4
-rw-r--r--src/connection-editor/nm-connection-list.c15
-rw-r--r--src/connection-editor/page-dcb.c27
-rw-r--r--src/connection-editor/vpn-helpers.c2
-rw-r--r--src/ethernet-dialog.c4
12 files changed, 113 insertions, 54 deletions
diff --git a/m4/compiler_warnings.m4 b/m4/compiler_options.m4
index b7acee58..fa11c522 100644
--- a/m4/compiler_warnings.m4
+++ b/m4/compiler_options.m4
@@ -1,17 +1,17 @@
-dnl Check whether a particular compiler flag works with code provided,
-dnl disable it in CFLAGS if the check fails.
-AC_DEFUN([NM_COMPILER_WARNING], [
+AC_DEFUN([_NM_COMPILER_FLAG], [
CFLAGS_SAVED="$CFLAGS"
- CFLAGS="$CFLAGS -Werror -W$1"
- AC_MSG_CHECKING(whether -W$1 works)
+ CFLAGS="$CFLAGS $GLIB_CFLAGS -Werror $1"
+ AC_MSG_CHECKING([whether $1 works as expected])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[]])], [
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[$2]])], [
AC_MSG_RESULT(yes)
- CFLAGS="$CFLAGS_SAVED -W$1"
+ CFLAGS="$CFLAGS_SAVED"
+ $3
],[
AC_MSG_RESULT(no)
- CFLAGS="$CFLAGS_SAVED -Wno-$1"
+ CFLAGS="$CFLAGS_SAVED"
+ $4
])
],[
AC_MSG_RESULT(not supported)
@@ -19,10 +19,25 @@ AC_DEFUN([NM_COMPILER_WARNING], [
])
])
+dnl Check whether a particular compiler flag is supported,
+dnl add it to CFLAGS if it is
+AC_DEFUN([NM_COMPILER_FLAG], [
+ _NM_COMPILER_FLAG([$1], [], [
+ CFLAGS="$CFLAGS $1"
+ $2
+ ], [$3])
+])
+
+dnl Check whether a particular warning is not emitted with code provided,
+dnl disable it in CFLAGS if the check fails.
+AC_DEFUN([NM_COMPILER_WARNING], [
+ _NM_COMPILER_FLAG([-W$1], [$2], [CFLAGS="$CFLAGS -W$1"], [CFLAGS="$CFLAGS -Wno-$1"])
+])
+
AC_DEFUN([NM_COMPILER_WARNINGS],
[AC_ARG_ENABLE(more-warnings,
AS_HELP_STRING([--enable-more-warnings], [Possible values: no/yes/error]),
- set_more_warnings="$enableval",set_more_warnings=error)
+ set_more_warnings="$enableval",set_more_warnings=yes)
AC_MSG_CHECKING(for more warnings)
if test "$GCC" = "yes" -a "$set_more_warnings" != "no"; then
AC_MSG_RESULT(yes)
@@ -40,7 +55,6 @@ if test "$GCC" = "yes" -a "$set_more_warnings" != "no"; then
dnl attach it to the CFLAGS.
NM_COMPILER_WARNING([unknown-warning-option], [])
- CFLAGS_SAVED="$CFLAGS"
CFLAGS_MORE_WARNINGS="-Wall -std=gnu89"
if test "x$set_more_warnings" = xerror; then
@@ -50,28 +64,19 @@ if test "$GCC" = "yes" -a "$set_more_warnings" != "no"; then
for option in -Wshadow -Wmissing-declarations -Wmissing-prototypes \
-Wdeclaration-after-statement -Wformat-security \
-Wfloat-equal -Wno-unused-parameter -Wno-sign-compare \
+ -Wno-duplicate-decl-specifier \
-Wstrict-prototypes \
- -fno-strict-aliasing -Wno-unused-but-set-variable \
+ -Wno-unused-but-set-variable \
+ -Wno-format-y2k \
-Wundef -Wimplicit-function-declaration \
- -Wpointer-arith -Winit-self \
- -Wmissing-include-dirs -Waggregate-return; do
+ -Wpointer-arith -Winit-self -Wformat-nonliteral \
+ -Wmissing-include-dirs -Wno-pragmas; do
dnl GCC 4.4 does not warn when checking for -Wno-* flags (https://gcc.gnu.org/wiki/FAQ#wnowarning)
- CFLAGS="$CFLAGS_MORE_WARNINGS $(printf '%s' "$option" | sed 's/^-Wno-/-W/') $CFLAGS_SAVED"
- AC_MSG_CHECKING([whether compiler understands $option])
- AC_TRY_COMPILE([], [],
- has_option=yes,
- has_option=no,)
- if test $has_option != no; then
- CFLAGS_MORE_WARNINGS="$CFLAGS_MORE_WARNINGS $option"
- fi
- AC_MSG_RESULT($has_option)
- unset has_option
+ _NM_COMPILER_FLAG([$(printf '%s' "$option" | sed 's/^-Wno-/-W/')], [],
+ [CFLAGS_MORE_WARNINGS="$CFLAGS_MORE_WARNINGS $option"], [])
done
unset option
- CFLAGS="$CFLAGS_SAVED"
- unset CFLAGS_SAVED
-
dnl Disable warnings triggered by known compiler problems
dnl https://bugzilla.gnome.org/show_bug.cgi?id=745821
diff --git a/shared/nm-macros-internal.h b/shared/nm-macros-internal.h
index 1f638bab..04e6a1ab 100644
--- a/shared/nm-macros-internal.h
+++ b/shared/nm-macros-internal.h
@@ -22,9 +22,17 @@
#ifndef __NM_MACROS_INTERNAL_H__
#define __NM_MACROS_INTERNAL_H__
+#include <stdlib.h>
+
/********************************************************/
-#define nm_auto(fcn) __attribute ((cleanup(fcn)))
+#define _nm_packed __attribute__ ((packed))
+#define _nm_unused __attribute__ ((unused))
+#define _nm_pure __attribute__ ((pure))
+#define _nm_const __attribute__ ((const))
+#define _nm_printf(a,b) __attribute__ ((__format__ (__printf__, a, b)))
+
+#define nm_auto(fcn) __attribute__ ((cleanup(fcn)))
/**
* nm_auto_free:
@@ -34,6 +42,13 @@
#define nm_auto_free nm_auto(_nm_auto_free_impl)
GS_DEFINE_CLEANUP_FUNCTION(void*, _nm_auto_free_impl, free)
+static inline void
+_nm_auto_unset_gvalue_impl (GValue *v)
+{
+ g_value_unset (v);
+}
+#define nm_auto_unset_gvalue nm_auto(_nm_auto_unset_gvalue_impl)
+
/********************************************************/
/* http://stackoverflow.com/a/11172679 */
@@ -285,10 +300,28 @@ _NM_IN_STRSET_streq (const char *x, const char *s)
/*****************************************************************************/
+/* glib/C provides the following kind of assertions:
+ * - assert() -- disable with NDEBUG
+ * - g_return_if_fail() -- disable with G_DISABLE_CHECKS
+ * - g_assert() -- disable with G_DISABLE_ASSERT
+ * but they are all enabled by default and usually even production builds have
+ * these kind of assertions enabled. It also means, that disabling assertions
+ * is an untested configuration, and might have bugs.
+ *
+ * Add our own assertion macro nm_assert(), which is disabled by default and must
+ * be explicitly enabled. They are useful for more expensive checks or checks that
+ * depend less on runtime conditions (that is, are generally expected to be true). */
+
+#ifndef NM_MORE_ASSERTS
+#define NM_MORE_ASSERTS 0
+#endif
+
#if NM_MORE_ASSERTS
#define nm_assert(cond) G_STMT_START { g_assert (cond); } G_STMT_END
+#define nm_assert_not_reached() G_STMT_START { g_assert_not_reached (); } G_STMT_END
#else
#define nm_assert(cond) G_STMT_START { if (FALSE) { if (cond) { } } } G_STMT_END
+#define nm_assert_not_reached() G_STMT_START { ; } G_STMT_END
#endif
/*****************************************************************************/
diff --git a/src/applet-dialogs.c b/src/applet-dialogs.c
index a3281bb9..10b56c04 100644
--- a/src/applet-dialogs.c
+++ b/src/applet-dialogs.c
@@ -993,11 +993,12 @@ applet_about_dialog_show (NMApplet *applet)
}
GtkWidget *
-applet_warning_dialog_show (const char *message)
+applet_missing_ui_warning_dialog_show (void)
{
GtkWidget *dialog;
- dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, message, NULL);
+ dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
+ _("The NetworkManager Applet could not find some required resources (the .ui file was not found)."));
/* Bash focus-stealing prevention in the face */
gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER_ALWAYS);
diff --git a/src/applet-dialogs.h b/src/applet-dialogs.h
index f197f13e..d3b5437f 100644
--- a/src/applet-dialogs.h
+++ b/src/applet-dialogs.h
@@ -31,7 +31,7 @@ void applet_info_dialog_show (NMApplet *applet);
void applet_about_dialog_show (NMApplet *applet);
-GtkWidget *applet_warning_dialog_show (const char *message);
+GtkWidget *applet_missing_ui_warning_dialog_show (void);
GtkWidget *applet_mobile_password_dialog_new (NMConnection *connection,
GtkEntry **out_secret_entry);
diff --git a/src/applet.c b/src/applet.c
index fc878159..b25585ba 100644
--- a/src/applet.c
+++ b/src/applet.c
@@ -1096,7 +1096,7 @@ applet_get_active_vpn_connection (NMApplet *applet,
{
const GPtrArray *active_list;
NMActiveConnection *ret = NULL;
- NMVpnConnectionState state;
+ NMVpnConnectionState state = NM_VPN_CONNECTION_STATE_UNKNOWN;
int i;
active_list = nm_client_get_active_connections (applet->nm_client);
diff --git a/src/connection-editor/ce-page.c b/src/connection-editor/ce-page.c
index 7e341438..6b7678a3 100644
--- a/src/connection-editor/ce-page.c
+++ b/src/connection-editor/ce-page.c
@@ -509,7 +509,9 @@ ce_page_get_next_available_name (const GPtrArray *connections, const char *forma
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;
diff --git a/src/connection-editor/nm-connection-editor.c b/src/connection-editor/nm-connection-editor.c
index 430ce8ff..ee682362 100644
--- a/src/connection-editor/nm-connection-editor.c
+++ b/src/connection-editor/nm-connection-editor.c
@@ -1093,10 +1093,9 @@ nm_connection_editor_set_busy (NMConnectionEditor *editor, gboolean busy)
static void
nm_connection_editor_dialog (GtkWindow *parent, GtkMessageType type, const char *heading,
- const char *format, va_list args)
+ const char *message)
{
GtkWidget *dialog;
- char *message;
dialog = gtk_message_dialog_new (parent,
GTK_DIALOG_DESTROY_WITH_PARENT,
@@ -1104,10 +1103,7 @@ nm_connection_editor_dialog (GtkWindow *parent, GtkMessageType type, const char
GTK_BUTTONS_CLOSE,
"%s", heading);
- message = g_strdup_vprintf (format, args);
-
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", message);
- g_free (message);
gtk_widget_show_all (dialog);
gtk_window_present (GTK_WINDOW (dialog));
@@ -1119,20 +1115,24 @@ void
nm_connection_editor_error (GtkWindow *parent, const char *heading, const char *format, ...)
{
va_list args;
+ gs_free char *message = NULL;
va_start (args, format);
- nm_connection_editor_dialog (parent, GTK_MESSAGE_ERROR, heading, format, args);
+ message = g_strdup_vprintf (format, args);
va_end (args);
+ nm_connection_editor_dialog (parent, GTK_MESSAGE_ERROR, heading, message);
}
void
nm_connection_editor_warning (GtkWindow *parent, const char *heading, const char *format, ...)
{
va_list args;
+ gs_free char *message = NULL;
va_start (args, format);
- nm_connection_editor_dialog (parent, GTK_MESSAGE_WARNING, heading, format, args);
+ message = g_strdup_vprintf (format, args);
va_end (args);
+ nm_connection_editor_dialog (parent, GTK_MESSAGE_WARNING, heading, message);
}
void
diff --git a/src/connection-editor/nm-connection-editor.h b/src/connection-editor/nm-connection-editor.h
index 6275baf5..76255ab2 100644
--- a/src/connection-editor/nm-connection-editor.h
+++ b/src/connection-editor/nm-connection-editor.h
@@ -99,11 +99,11 @@ void nm_connection_editor_set_busy (NMConnectionEditor *editor, g
void nm_connection_editor_error (GtkWindow *parent,
const char *heading,
const char *format,
- ...);
+ ...) _nm_printf(3,4);
void nm_connection_editor_warning (GtkWindow *parent,
const char *heading,
const char *format,
- ...);
+ ...) _nm_printf(3,4);
void nm_connection_editor_inter_page_set_value (NMConnectionEditor *editor,
InterPageChangeType type,
diff --git a/src/connection-editor/nm-connection-list.c b/src/connection-editor/nm-connection-list.c
index 7f2b3c7c..0bd1db01 100644
--- a/src/connection-editor/nm-connection-list.c
+++ b/src/connection-editor/nm-connection-list.c
@@ -895,7 +895,6 @@ void
nm_connection_list_create (NMConnectionList *self, GType ctype, const char *detail)
{
ConnectionTypeData *types;
- char *error_msg;
int i;
g_return_if_fail (NM_IS_CONNECTION_LIST (self));
@@ -908,13 +907,13 @@ nm_connection_list_create (NMConnectionList *self, GType ctype, const char *deta
break;
}
if (!types[i].name) {
- if (ctype == NM_TYPE_SETTING_VPN)
- error_msg = g_strdup (_("No VPN plugins are installed."));
- else
- error_msg = g_strdup_printf (_("Don't know how to create '%s' connections"), g_type_name (ctype));
-
- nm_connection_editor_error (NULL, _("Error creating connection"), error_msg);
- g_free (error_msg);
+ if (ctype == NM_TYPE_SETTING_VPN) {
+ nm_connection_editor_error (NULL, _("Error creating connection"),
+ _("No VPN plugins are installed."));
+ } else {
+ nm_connection_editor_error (NULL, _("Error creating connection"),
+ _("Don't know how to create '%s' connections"), g_type_name (ctype));
+ }
} else {
new_connection_of_type (GTK_WINDOW (self->dialog),
detail,
diff --git a/src/connection-editor/page-dcb.c b/src/connection-editor/page-dcb.c
index 05ba4310..4d995d3d 100644
--- a/src/connection-editor/page-dcb.c
+++ b/src/connection-editor/page-dcb.c
@@ -47,6 +47,25 @@ typedef struct {
/***************************************************************************/
+static char *
+_strdup_printf_uint (const char *format, guint i)
+{
+#if NM_MORE_ASSERTS
+ const char *f = format;
+
+ g_assert (f);
+ f = strchr (f, '%');
+ g_assert (f);
+ f++;
+ g_assert (!strchr (f, '%'));
+ g_assert (f[0] == 'u');
+#endif
+
+ NM_PRAGMA_WARNING_DISABLE("-Wformat-nonliteral")
+ return g_strdup_printf (format, i);
+ NM_PRAGMA_WARNING_REENABLE
+}
+
static void
pfc_dialog_show (CEPageDcb *self)
{
@@ -107,7 +126,7 @@ uint_entries_validate (GtkBuilder *builder, const char *fmt, gint max, gboolean
gdk_rgba_parse (&bgcolor, "red3");
for (i = 0; i < 8; i++) {
- tmp = g_strdup_printf (fmt, i);
+ tmp = _strdup_printf_uint (fmt, i);
entry = GTK_ENTRY (gtk_builder_get_object (builder, tmp));
g_free (tmp);
g_assert (entry);
@@ -166,7 +185,7 @@ combos_handle (GtkBuilder *builder,
guint i, num;
for (i = 0; i < 8; i++) {
- tmp = g_strdup_printf (fmt, i);
+ tmp = _strdup_printf_uint (fmt, i);
combo = GTK_COMBO_BOX (gtk_builder_get_object (builder, tmp));
g_free (tmp);
g_assert (combo);
@@ -216,7 +235,7 @@ uint_entries_handle (GtkBuilder *builder,
const char *text;
for (i = 0; i < 8; i++) {
- tmp = g_strdup_printf (fmt, i);
+ tmp = _strdup_printf_uint (fmt, i);
entry = GTK_ENTRY (gtk_builder_get_object (builder, tmp));
g_free (tmp);
g_assert (entry);
@@ -255,7 +274,7 @@ bool_entries_handle (GtkBuilder *builder,
guint i;
for (i = 0; i < 8; i++) {
- tmp = g_strdup_printf (fmt, i);
+ tmp = _strdup_printf_uint (fmt, i);
toggle = GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, tmp));
g_free (tmp);
g_assert (toggle);
diff --git a/src/connection-editor/vpn-helpers.c b/src/connection-editor/vpn-helpers.c
index ecfc850c..35823c7b 100644
--- a/src/connection-editor/vpn-helpers.c
+++ b/src/connection-editor/vpn-helpers.c
@@ -46,7 +46,7 @@ _sort_vpn_plugins (NMVpnPluginInfo *aa, NMVpnPluginInfo *bb)
}
GSList *
-vpn_get_plugins ()
+vpn_get_plugins (void)
{
static gboolean plugins_loaded = FALSE;
static GSList *plugins = NULL;
diff --git a/src/ethernet-dialog.c b/src/ethernet-dialog.c
index 6cbe4551..e5aaa846 100644
--- a/src/ethernet-dialog.c
+++ b/src/ethernet-dialog.c
@@ -83,7 +83,7 @@ nma_ethernet_dialog_new (NMConnection *connection)
if (!gtk_builder_add_from_file (builder, UIDIR "/8021x.ui", &error)) {
g_warning ("Couldn't load builder file: %s", error->message);
g_error_free (error);
- applet_warning_dialog_show (_("The NetworkManager Applet could not find some required resources (the .ui file was not found)."));
+ applet_missing_ui_warning_dialog_show ();
g_object_unref (builder);
return NULL;
}
@@ -91,7 +91,7 @@ nma_ethernet_dialog_new (NMConnection *connection)
dialog = (GtkWidget *) gtk_builder_get_object (builder, "8021x_dialog");
if (!dialog) {
g_warning ("Couldn't find wireless_dialog widget.");
- applet_warning_dialog_show (_("The NetworkManager Applet could not find some required resources (the .ui file was not found)."));
+ applet_missing_ui_warning_dialog_show ();
g_object_unref (builder);
return NULL;
}