From 746a13bdcdbe79e354238d67f90c473ec83f17a4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 27 Jul 2014 04:37:12 +0200 Subject: [PATCH 01/21] libnm-glib/test: fix crash in test-remote-settings-client test_make_invisible() forgot to disconnect handler invis_removed_cb(). Later, during test_remove_connection(), the connection will be eventually removed and the callback will corrupt the stack by writing to the '&done' user data. Signed-off-by: Thomas Haller (cherry picked from commit d6b3ef0819dde4e6bc514b815f6259f1eaffa150) --- libnm-glib/tests/test-remote-settings-client.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libnm-glib/tests/test-remote-settings-client.c b/libnm-glib/tests/test-remote-settings-client.c index a13e8311cb..5fcd439c87 100644 --- a/libnm-glib/tests/test-remote-settings-client.c +++ b/libnm-glib/tests/test-remote-settings-client.c @@ -186,6 +186,8 @@ test_make_invisible (void) } while ((done == FALSE) && (now - start < 5)); test_assert (done == TRUE); + g_signal_handlers_disconnect_by_func (remote, G_CALLBACK (invis_removed_cb), &done); + /* Ensure NMRemoteSettings no longer has the connection */ list = nm_remote_settings_list_connections (settings); for (iter = list; iter; iter = g_slist_next (iter)) { From e2edf1afd6fa0a8e66ddd93d74e5f5781deacd47 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 27 Jul 2014 04:54:13 +0200 Subject: [PATCH 02/21] libnm-glib/test: add asserts to test-remote-settings-client - register a weak references and ensure that the connection is removed when expected. - disconnect the vis_new_connection_cb() handler Signed-off-by: Thomas Haller (cherry picked from commit 1de6d83e29b43ece726f49b43aeb632543aa42be) --- libnm-glib/tests/test-remote-settings-client.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libnm-glib/tests/test-remote-settings-client.c b/libnm-glib/tests/test-remote-settings-client.c index 5fcd439c87..12501ee361 100644 --- a/libnm-glib/tests/test-remote-settings-client.c +++ b/libnm-glib/tests/test-remote-settings-client.c @@ -49,7 +49,7 @@ cleanup (void) #define test_assert(condition) \ do { \ - gboolean _condition = ( condition ); \ + gboolean _condition = !!( condition ); \ \ if (G_UNLIKELY (!_condition)) { \ cleanup (); \ @@ -70,6 +70,7 @@ add_cb (NMRemoteSettings *s, *((gboolean *) user_data) = TRUE; remote = connection; + g_object_add_weak_pointer (G_OBJECT (connection), (void **) &remote); } #define TEST_CON_ID "blahblahblah" @@ -186,6 +187,7 @@ test_make_invisible (void) } while ((done == FALSE) && (now - start < 5)); test_assert (done == TRUE); + g_assert (remote); g_signal_handlers_disconnect_by_func (remote, G_CALLBACK (invis_removed_cb), &done); /* Ensure NMRemoteSettings no longer has the connection */ @@ -198,6 +200,7 @@ test_make_invisible (void) } /* And ensure the invisible connection no longer has any settings */ + g_assert (remote); nm_connection_for_each_setting_value (NM_CONNECTION (remote), invis_has_settings_cb, &has_settings); @@ -253,8 +256,11 @@ test_make_visible (void) } while ((new == NULL) && (now - start < 5)); /* Ensure the new connection is the same as the one we made visible again */ + test_assert (new); test_assert (new == remote); + g_signal_handlers_disconnect_by_func (settings, G_CALLBACK (vis_new_connection_cb), &new); + /* Ensure NMRemoteSettings has the connection */ list = nm_remote_settings_list_connections (settings); for (iter = list; iter; iter = g_slist_next (iter)) { @@ -311,6 +317,8 @@ test_remove_connection (void) test_assert (g_slist_length (list) > 0); connection = NM_REMOTE_CONNECTION (list->data); + g_assert (connection); + g_assert (remote == connection); path = g_strdup (nm_connection_get_path (NM_CONNECTION (connection))); g_signal_connect (connection, "removed", G_CALLBACK (removed_cb), &done); @@ -330,6 +338,8 @@ test_remove_connection (void) } while ((done == FALSE) && (now - start < 5)); test_assert (done == TRUE); + g_assert (!remote); + /* Ensure NMRemoteSettings no longer has the connection */ list = nm_remote_settings_list_connections (settings); for (iter = list; iter; iter = g_slist_next (iter)) { From b44f7565ec795e6d01800496d3d6e4784642ad87 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 26 Jul 2014 20:11:31 +0200 Subject: [PATCH 03/21] build/clang: fix detection of valid warning compiler flags clang does not exit with error when it is called with an unrecognized (warning) option. Instead it just prints a warning that makes the configure script believe the warning is supported. Later, during build we might pass -Werror, which causes clang to fail due to unrecognized arguments. Fix the script to detect compiler warnings by passing '-Werror=unknown-warning-option', which lets clang fail too. Signed-off-by: Thomas Haller (cherry picked from commit 5009f2c7a3dc4ba6d197cbe62029fd2a0c78ab8a) --- m4/compiler_warnings.m4 | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/m4/compiler_warnings.m4 b/m4/compiler_warnings.m4 index 357ff0e7e0..0512ba1e0a 100644 --- a/m4/compiler_warnings.m4 +++ b/m4/compiler_warnings.m4 @@ -7,6 +7,23 @@ if test "$GCC" = "yes" -a "$set_more_warnings" != "no"; then AC_MSG_RESULT(yes) CFLAGS="-Wall -std=gnu89 $CFLAGS" + dnl clang only warns about unknown warnings, unless + dnl called with "-Werror=unknown-warning-option" + dnl Test if the compiler supports that, and if it does + dnl attach it to the CFLAGS. + SAVE_CFLAGS="$CFLAGS" + EXTRA_CFLAGS="-Werror=unknown-warning-option" + CFLAGS="$SAVE_CFLAGS $EXTRA_CFLAGS" + AC_TRY_COMPILE([], [], + has_option=yes, + has_option=no,) + if test $has_option = no; then + EXTRA_CFLAGS= + fi + CFLAGS="$SAVE_CFLAGS" + unset has_option + unset SAVE_CFLAGS + for option in -Wshadow -Wmissing-declarations -Wmissing-prototypes \ -Wdeclaration-after-statement -Wformat-security \ -Wfloat-equal -Wno-unused-parameter -Wno-sign-compare \ @@ -15,19 +32,22 @@ if test "$GCC" = "yes" -a "$set_more_warnings" != "no"; then -Wpointer-arith -Winit-self \ -Wmissing-include-dirs -Waggregate-return; do SAVE_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS $option" + CFLAGS="$CFLAGS $EXTRA_CFLAGS $option" AC_MSG_CHECKING([whether gcc understands $option]) AC_TRY_COMPILE([], [], has_option=yes, has_option=no,) if test $has_option = no; then CFLAGS="$SAVE_CFLAGS" + else + CFLAGS="$SAVE_CFLAGS $option" fi AC_MSG_RESULT($has_option) unset has_option unset SAVE_CFLAGS done unset option + unset EXTRA_CFLAGS if test "x$set_more_warnings" = xerror; then CFLAGS="$CFLAGS -Werror" fi From 078dd82d1908c517d95e33356e63a1326afcaaff Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 26 Jul 2014 21:13:52 +0200 Subject: [PATCH 04/21] all: add compatibility macros to ignore deprecation warnings for clang For clang, the defines G_GNUC_BEGIN_IGNORE_DEPRECATIONS and G_GNUC_END_IGNORE_DEPRECATIONS are not working. Redefine them for clang in our glib compatibility wrapper. Signed-off-by: Thomas Haller (cherry picked from commit b461bf54f2016791e13eee6164a6669c1b747010) --- cli/src/settings.c | 1 + include/nm-glib-compat.h | 17 +++++++++++++++++ include/nm-gvaluearray-compat.h | 2 ++ tui/newt/nmt-newt-utils.c | 1 + 4 files changed, 21 insertions(+) diff --git a/cli/src/settings.c b/cli/src/settings.c index 0fc708b352..876393f4fd 100644 --- a/cli/src/settings.c +++ b/cli/src/settings.c @@ -29,6 +29,7 @@ #include "utils.h" #include "common.h" #include "settings.h" +#include "nm-glib-compat.h" /* Forward declarations */ static char *wep_key_type_to_string (NMWepKeyType type); diff --git a/include/nm-glib-compat.h b/include/nm-glib-compat.h index cfaddb7d31..81d80f7c5b 100644 --- a/include/nm-glib-compat.h +++ b/include/nm-glib-compat.h @@ -27,8 +27,25 @@ #include #include + +#ifdef __clang__ + +#undef G_GNUC_BEGIN_IGNORE_DEPRECATIONS +#undef G_GNUC_END_IGNORE_DEPRECATIONS + +#define G_GNUC_BEGIN_IGNORE_DEPRECATIONS \ + _Pragma("clang diagnostic push") \ + _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") + +#define G_GNUC_END_IGNORE_DEPRECATIONS \ + _Pragma("clang diagnostic pop") + +#endif + + #include "nm-gvaluearray-compat.h" + #if !GLIB_CHECK_VERSION(2,34,0) static inline void g_type_ensure (GType type) diff --git a/include/nm-gvaluearray-compat.h b/include/nm-gvaluearray-compat.h index e26ce37174..0fb4bd6e94 100644 --- a/include/nm-gvaluearray-compat.h +++ b/include/nm-gvaluearray-compat.h @@ -23,6 +23,8 @@ #include +#include "nm-glib-compat.h" + #define g_value_array_get_type() \ G_GNUC_EXTENSION ({ \ G_GNUC_BEGIN_IGNORE_DEPRECATIONS \ diff --git a/tui/newt/nmt-newt-utils.c b/tui/newt/nmt-newt-utils.c index 68d8c449e5..70a65a8489 100644 --- a/tui/newt/nmt-newt-utils.c +++ b/tui/newt/nmt-newt-utils.c @@ -30,6 +30,7 @@ #include +#include "nm-glib-compat.h" #include "nmt-newt-utils.h" static void From c8b57acd689a97f06a6676d9f87a0af111f84686 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 26 Jul 2014 21:24:38 +0200 Subject: [PATCH 05/21] libnm-util: fix warning converting between enum types in nm-setting-8021x.c clang warns: make[4]: Entering directory `./NetworkManager/libnm-util' CC nm-setting-8021x.lo nm-setting-8021x.c:1824:17: error: implicit conversion from enumeration type 'NMCryptoFileFormat' to different enumeration type 'NMSetting8021xCKFormat' [-Werror,-Wenum-conversion] *out_format = format; ~ ^~~~~~ nm-setting-8021x.c:2135:17: error: implicit conversion from enumeration type 'NMCryptoFileFormat' to different enumeration type 'NMSetting8021xCKFormat' [-Werror,-Wenum-conversion] *out_format = format; ~ ^~~~~~ Signed-off-by: Thomas Haller (cherry picked from commit 22ca469011c37ee64dbec0958d54e263fb677f7f) --- libnm-util/nm-setting-8021x.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libnm-util/nm-setting-8021x.c b/libnm-util/nm-setting-8021x.c index d85b87b891..162b623049 100644 --- a/libnm-util/nm-setting-8021x.c +++ b/libnm-util/nm-setting-8021x.c @@ -92,6 +92,11 @@ NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_802_1X) #define NM_SETTING_802_1X_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_802_1X, NMSetting8021xPrivate)) +G_STATIC_ASSERT ( (NM_SETTING_802_1X_CK_FORMAT_UNKNOWN == (NMSetting8021xCKFormat) NM_CRYPTO_FILE_FORMAT_UNKNOWN) ); +G_STATIC_ASSERT ( (NM_SETTING_802_1X_CK_FORMAT_X509 == (NMSetting8021xCKFormat) NM_CRYPTO_FILE_FORMAT_X509) ); +G_STATIC_ASSERT ( (NM_SETTING_802_1X_CK_FORMAT_RAW_KEY == (NMSetting8021xCKFormat) NM_CRYPTO_FILE_FORMAT_RAW_KEY) ); +G_STATIC_ASSERT ( (NM_SETTING_802_1X_CK_FORMAT_PKCS12 == (NMSetting8021xCKFormat) NM_CRYPTO_FILE_FORMAT_PKCS12) ); + typedef struct { GSList *eap; /* GSList of strings */ char *identity; @@ -1824,7 +1829,7 @@ nm_setting_802_1x_set_private_key (NMSetting8021x *setting, g_object_notify (G_OBJECT (setting), NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD); if (out_format) - *out_format = format; + *out_format = (NMSetting8021xCKFormat) format; return priv->private_key != NULL; } @@ -2135,7 +2140,7 @@ nm_setting_802_1x_set_phase2_private_key (NMSetting8021x *setting, g_object_notify (G_OBJECT (setting), NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD); if (out_format) - *out_format = format; + *out_format = (NMSetting8021xCKFormat) format; return priv->phase2_private_key != NULL; } From f80ae70577264f7daaa14f61b958ae68e2668057 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 26 Jul 2014 21:38:30 +0200 Subject: [PATCH 06/21] libnm-glib: fix warning about redefining typedef RemoteCall clang warns: make[4]: Entering directory `./NetworkManager/libnm-glib' CC libnm_glib_la-nm-remote-connection.lo nm-remote-connection.c:77:3: error: redefinition of typedef 'RemoteCall' is a C11 feature [-Werror,-Wtypedef-redefinition] } RemoteCall; ^ nm-remote-connection.c:67:27: note: previous definition is here typedef struct RemoteCall RemoteCall; ^ Signed-off-by: Thomas Haller (cherry picked from commit 0238f8f8e2d435f0a61ba2c7c4ffe2ec3129580b) --- libnm-glib/nm-remote-connection.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libnm-glib/nm-remote-connection.c b/libnm-glib/nm-remote-connection.c index 38911a43b4..c91060fb05 100644 --- a/libnm-glib/nm-remote-connection.c +++ b/libnm-glib/nm-remote-connection.c @@ -70,13 +70,13 @@ typedef struct RemoteCall RemoteCall; typedef void (*RemoteCallFetchResultCb) (RemoteCall *call, DBusGProxyCall *proxy_call, GError *error); -typedef struct RemoteCall { +struct RemoteCall { NMRemoteConnection *self; DBusGProxyCall *call; RemoteCallFetchResultCb fetch_result_cb; GFunc callback; gpointer user_data; -} RemoteCall; +}; typedef struct { DBusGConnection *bus; From bef8723189523b550aad1adc6d7b1617a7a26c53 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 26 Jul 2014 21:41:41 +0200 Subject: [PATCH 07/21] core: fix warning about comparing unsigned enum values being positive clang warns: make[4]: Entering directory `./NetworkManager/src' CC nm-device.lo devices/nm-device.c:367:12: error: comparison of unsigned enum expression >= 0 is always true [-Werror,-Wtautological-compare] if (state >= 0 && state < G_N_ELEMENTS (state_table)) ~~~~~ ^ ~ devices/nm-device.c:443:13: error: comparison of unsigned enum expression >= 0 is always true [-Werror,-Wtautological-compare] if (reason >= 0 && reason < G_N_ELEMENTS (reason_table)) ~~~~~~ ^ ~ Signed-off-by: Thomas Haller (cherry picked from commit a2a36d845066a5e3ad1b6d2953993a1a433340ff) Conflicts: src/dhcp-manager/nm-dhcp-client.c --- src/devices/nm-device.c | 4 ++-- src/devices/wwan/nm-modem.c | 2 +- src/dhcp-manager/nm-dhcp-client.c | 2 +- src/vpn-manager/nm-vpn-connection.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 4788a604db..291f03f619 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -366,7 +366,7 @@ static const char *state_table[] = { static const char * queued_state_to_string (NMDeviceState state) { - if (state >= 0 && state < G_N_ELEMENTS (state_table)) + if ((gsize) state < G_N_ELEMENTS (state_table)) return state_table[state]; return state_table[NM_DEVICE_STATE_UNKNOWN]; } @@ -442,7 +442,7 @@ static const char *reason_table[] = { static const char * reason_to_string (NMDeviceStateReason reason) { - if (reason >= 0 && reason < G_N_ELEMENTS (reason_table)) + if ((gsize) reason < G_N_ELEMENTS (reason_table)) return reason_table[reason]; return reason_table[NM_DEVICE_STATE_REASON_UNKNOWN]; } diff --git a/src/devices/wwan/nm-modem.c b/src/devices/wwan/nm-modem.c index fd3b4a3691..40428e27a9 100644 --- a/src/devices/wwan/nm-modem.c +++ b/src/devices/wwan/nm-modem.c @@ -126,7 +126,7 @@ static const char *state_table[] = { const char * nm_modem_state_to_string (NMModemState state) { - if (state >= 0 && state < G_N_ELEMENTS (state_table)) + if ((gsize) state < G_N_ELEMENTS (state_table)) return state_table[state]; return NULL; } diff --git a/src/dhcp-manager/nm-dhcp-client.c b/src/dhcp-manager/nm-dhcp-client.c index 03c11c74d4..1f186f3256 100644 --- a/src/dhcp-manager/nm-dhcp-client.c +++ b/src/dhcp-manager/nm-dhcp-client.c @@ -607,7 +607,7 @@ static const char *state_table[] = { static const char * state_to_string (NMDHCPState state) { - if (state >= 0 && state < G_N_ELEMENTS (state_table)) + if ((gsize) state < G_N_ELEMENTS (state_table)) return state_table[state]; return NULL; } diff --git a/src/vpn-manager/nm-vpn-connection.c b/src/vpn-manager/nm-vpn-connection.c index d66dcfdb73..a52c590e20 100644 --- a/src/vpn-manager/nm-vpn-connection.c +++ b/src/vpn-manager/nm-vpn-connection.c @@ -662,7 +662,7 @@ static const char *state_table[] = { static const char * vpn_state_to_string (VpnState state) { - if (state >= 0 && state < G_N_ELEMENTS (state_table)) + if ((gsize) state < G_N_ELEMENTS (state_table)) return state_table[state]; return "unknown"; } From 5c7b594dd4a916ccb768744b66a0df325a51736d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 26 Jul 2014 21:46:34 +0200 Subject: [PATCH 08/21] core: fix wrong device state change on failure in NMDeviceEthernet Due to a bug, when dcb fails it would change the device state to NM_DEVICE_STATE_UNKNOWN (zero), instead of NM_DEVICE_STATE_FAILED. clang warns: make[4]: Entering directory `./NetworkManager/src' CC nm-device-ethernet.lo devices/nm-device-ethernet.c:1237:30: error: implicit conversion from enumeration type 'enum NMActStageReturn' to different enumeration type 'NMDeviceState' [-Werror,-Wenum-conversion] NM_ACT_STAGE_RETURN_FAILURE, ^~~~~~~~~~~~~~~~~~~~~~~~~~~ devices/nm-device-ethernet.c:1261:30: error: implicit conversion from enumeration type 'enum NMActStageReturn' to different enumeration type 'NMDeviceState' [-Werror,-Wenum-conversion] NM_ACT_STAGE_RETURN_FAILURE, ^~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Thomas Haller (cherry picked from commit 657ea51008f4642d8a2aa950b4c36ef4eb49b83e) --- src/devices/nm-device-ethernet.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c index f4a90c7473..d0d31189a3 100644 --- a/src/devices/nm-device-ethernet.c +++ b/src/devices/nm-device-ethernet.c @@ -1234,7 +1234,7 @@ dcb_state (NMDevice *device, gboolean timeout) if (!dcb_enable (device)) { dcb_carrier_cleanup (device); nm_device_state_changed (device, - NM_ACT_STAGE_RETURN_FAILURE, + NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_DCB_FCOE_FAILED); } } @@ -1258,7 +1258,7 @@ dcb_state (NMDevice *device, gboolean timeout) if (!dcb_configure (device)) { dcb_carrier_cleanup (device); nm_device_state_changed (device, - NM_ACT_STAGE_RETURN_FAILURE, + NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_DCB_FCOE_FAILED); } } From 48a1a82f94c9ba9f0f9f77d8eb290a3660b6d79d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 26 Jul 2014 21:58:57 +0200 Subject: [PATCH 09/21] platform: fix warning warning about unused variable The variable is not actually unused, because it is used to free the nl_object instance. clang warns: make[4]: Entering directory `./NetworkManager/src' CC nm-linux-platform.lo platform/nm-linux-platform.c:1746:35: error: unused variable 'obj_cleanup' [-Werror,-Wunused-variable] auto_nl_object struct nl_object *obj_cleanup = obj; ^ Signed-off-by: Thomas Haller (cherry picked from commit 971dfc773f061ed6f1ba81e59c826b06fb37c19b) --- src/platform/nm-linux-platform.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index c18132760c..d6c0a44ca9 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -1723,15 +1723,14 @@ add_object (NMPlatform *platform, struct nl_object *obj) /* Decreases the reference count if @obj for convenience */ static gboolean -delete_object (NMPlatform *platform, struct nl_object *obj, gboolean do_refresh_object) +delete_object (NMPlatform *platform, struct nl_object *object, gboolean do_refresh_object) { NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform); - auto_nl_object struct nl_object *obj_cleanup = obj; - struct nl_object *object = obj; int object_type; int nle; + gboolean result = FALSE; - object_type = object_type_from_nl_object (obj); + object_type = object_type_from_nl_object (object); g_return_val_if_fail (object_type != OBJECT_TYPE_UNKNOWN, FALSE); switch (object_type) { @@ -1774,14 +1773,18 @@ delete_object (NMPlatform *platform, struct nl_object *obj, gboolean do_refresh_ goto DEFAULT; DEFAULT: default: - error ("Netlink error deleting %s: %s (%d)", to_string_object (platform, obj), nl_geterror (nle), nle); - return FALSE; + error ("Netlink error deleting %s: %s (%d)", to_string_object (platform, object), nl_geterror (nle), nle); + goto out; } if (do_refresh_object) refresh_object (platform, object, TRUE, NM_PLATFORM_REASON_INTERNAL); - return TRUE; + result = TRUE; + +out: + nl_object_put (object); + return result; } static void From 87b6917dc7575f688f9c87439d40e9db65cd72cc Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 26 Jul 2014 22:06:40 +0200 Subject: [PATCH 10/21] platform: fix warning initializing static array freq_policy Since kernel commit 8fe02e167efa8ed4a4503a5eedc0f49fcb7e3eb9, the value NL80211_FREQUENCY_ATTR_NO_IR replaces PASSIVE_SCAN and NO_IBSS. Hence their numerical values are identical and cause the following compiler warning. clang warns: make[4]: Entering directory `./NetworkManager/src' CC wifi-utils-nl80211.lo platform/wifi/wifi-utils-nl80211.c:683:48: error: initializer overrides prior initialization of this subobject [-Werror,-Winitializer-overrides] [NL80211_FREQUENCY_ATTR_NO_IBSS] = { .type = NLA_FLAG }, ^~~~~~~~ platform/wifi/wifi-utils-nl80211.c:682:53: note: previous initialization is here [NL80211_FREQUENCY_ATTR_PASSIVE_SCAN] = { .type = NLA_FLAG }, ^~~~~~~~ Signed-off-by: Thomas Haller (cherry picked from commit e31474f5d4cd51cbc1069e0ff7806a1045a14f12) --- src/platform/wifi/wifi-utils-nl80211.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/platform/wifi/wifi-utils-nl80211.c b/src/platform/wifi/wifi-utils-nl80211.c index 25ebd1b3ce..b2de4e29be 100644 --- a/src/platform/wifi/wifi-utils-nl80211.c +++ b/src/platform/wifi/wifi-utils-nl80211.c @@ -679,11 +679,20 @@ static int nl80211_wiphy_info_handler (struct nl_msg *msg, void *arg) static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = { [NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 }, [NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG }, +#ifdef NL80211_FREQUENCY_ATTR_NO_IR + [NL80211_FREQUENCY_ATTR_NO_IR] = { .type = NLA_FLAG }, +#else [NL80211_FREQUENCY_ATTR_PASSIVE_SCAN] = { .type = NLA_FLAG }, [NL80211_FREQUENCY_ATTR_NO_IBSS] = { .type = NLA_FLAG }, +#endif [NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG }, [NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 }, }; +#ifdef NL80211_FREQUENCY_ATTR_NO_IR + G_STATIC_ASSERT (NL80211_FREQUENCY_ATTR_PASSIVE_SCAN == NL80211_FREQUENCY_ATTR_NO_IR && NL80211_FREQUENCY_ATTR_NO_IBSS == NL80211_FREQUENCY_ATTR_NO_IR); +#else + G_STATIC_ASSERT (NL80211_FREQUENCY_ATTR_PASSIVE_SCAN != NL80211_FREQUENCY_ATTR_NO_IBSS); +#endif if (nla_parse (tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen (gnlh, 0), NULL) < 0) From c10d4315646d73e488ece8994325f13b41f6fdb3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 26 Jul 2014 22:44:25 +0200 Subject: [PATCH 11/21] vpn: fix warning in vpn-manager about implicit conversion of enum types This bug has no real consequense, because the numerical values of the enum values are identical. clang warns: make[4]: Entering directory `./NetworkManager/src' CC nm-vpn-connection.lo vpn-manager/nm-vpn-connection.c:179:10: error: implicit conversion from enumeration type 'VpnState' to different enumeration type 'NMVPNConnectionState' (aka 'enum NMVPNConnectionState') [-Werror,-Wenum-conversion] return STATE_UNKNOWN; ~~~~~~ ^~~~~~~~~~~~~ Signed-off-by: Thomas Haller (cherry picked from commit 45c5365d8533136da84a2aae8313885d01147c1b) --- src/vpn-manager/nm-vpn-connection.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vpn-manager/nm-vpn-connection.c b/src/vpn-manager/nm-vpn-connection.c index a52c590e20..b9f204ce2e 100644 --- a/src/vpn-manager/nm-vpn-connection.c +++ b/src/vpn-manager/nm-vpn-connection.c @@ -173,7 +173,7 @@ _state_to_nm_vpn_state (VpnState state) case STATE_FAILED: return NM_VPN_CONNECTION_STATE_FAILED; default: - return STATE_UNKNOWN; + return NM_VPN_CONNECTION_STATE_UNKNOWN; } } From 40fb65aa92303c81c39405a471788f52533ee5b5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 26 Jul 2014 22:48:36 +0200 Subject: [PATCH 12/21] core: fix warning calling non-returning g_error() g_error() does not return, but clang seems not to understand that and gives the following warning. make[4]: Entering directory `./NetworkManager/src' CC NetworkManagerUtils.lo NetworkManagerUtils.c:1584:1: error: control may reach end of non-void function [-Werror,-Wreturn-type] } ^ Signed-off-by: Thomas Haller (cherry picked from commit 43df0e9ae41a7d31db93564e7887f3bd588b80d2) --- src/NetworkManagerUtils.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c index 0aaa344f91..7854364138 100644 --- a/src/NetworkManagerUtils.c +++ b/src/NetworkManagerUtils.c @@ -1208,5 +1208,6 @@ fail: else nm_log_err (LOGD_CORE, "Failed asserting path component: \"%s\"", name); g_error ("FATAL: Failed asserting path component: %s", name ? name : "(null)"); + g_assert_not_reached (); } From ef46ad5031c30cc4f539eb986bd5b5a07b753b44 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 26 Jul 2014 22:59:21 +0200 Subject: [PATCH 13/21] olpc: fix wrong state change reason for device NM_VPN_CONNECTION_STATE_REASON_USER_DISCONNECTED would map to NM_DEVICE_STATE_REASON_NOW_MANAGED. clang warns: make[6]: Entering directory `./NetworkManager/src/devices/wifi' CC nm-device-olpc-mesh.lo nm-device-olpc-mesh.c:193:28: error: implicit conversion from enumeration type 'enum NMVPNConnectionStateReason' to different enumeration type 'NMDeviceStateReason' [-Werror,-Wenum-conversion] NM_VPN_CONNECTION_STATE_REASON_USER_DISCONNECTED); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ nm-device-olpc-mesh.c:319:27: error: implicit conversion from enumeration type 'enum NMVPNConnectionStateReason' to different enumeration type 'NMDeviceStateReason' [-Werror,-Wenum-conversion] NM_VPN_CONNECTION_STATE_REASON_USER_DISCONNECTED); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Thomas Haller (cherry picked from commit e543909afc313416b9d8e7da82761c1470816471) --- src/devices/wifi/nm-device-olpc-mesh.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/devices/wifi/nm-device-olpc-mesh.c b/src/devices/wifi/nm-device-olpc-mesh.c index 85214a7005..09b525e408 100644 --- a/src/devices/wifi/nm-device-olpc-mesh.c +++ b/src/devices/wifi/nm-device-olpc-mesh.c @@ -189,7 +189,7 @@ act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason) /* FIXME: VPN stuff here is a bug; but we can't really change API now... */ nm_device_state_changed (NM_DEVICE (priv->companion), NM_DEVICE_STATE_DISCONNECTED, - NM_VPN_CONNECTION_STATE_REASON_USER_DISCONNECTED); + NM_DEVICE_STATE_REASON_USER_REQUESTED); nm_log_info (LOGD_OLPC, "(%s): companion %s disconnected", nm_device_get_iface (dev), nm_device_get_iface (priv->companion)); @@ -315,7 +315,7 @@ companion_state_changed_cb (NMDeviceWifi *companion, /* FIXME: VPN stuff here is a bug; but we can't really change API now... */ nm_device_state_changed (NM_DEVICE (self), NM_DEVICE_STATE_DISCONNECTED, - NM_VPN_CONNECTION_STATE_REASON_USER_DISCONNECTED); + NM_DEVICE_STATE_REASON_USER_REQUESTED); } static gboolean From 93ee9d55d4783b24ccd8ce4aadfa0c19bc2b768d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 26 Jul 2014 23:02:44 +0200 Subject: [PATCH 14/21] ifcfg-rh: fix warning about duplicate const when declaring string clang warns: make[7]: Entering directory `./NetworkManager/src/settings/plugins/ifcfg-rh' CC writer.lo writer.c:2505:20: error: duplicate 'const' declaration specifier [-Werror,-Wduplicate-decl-specifier] static const char const as_dash[] = "\\][|/=()!"; ^~~~~~ CC utils.lo utils.c:40:20: error: duplicate 'const' declaration specifier [-Werror,-Wduplicate-decl-specifier] static const char const drop_chars[] = "\r\n"; /* drop CR and LF */ ^~~~~~ Signed-off-by: Thomas Haller (cherry picked from commit 4ca6274e2b026eb628d31dab1996004acdc6e441) --- src/settings/plugins/ifcfg-rh/utils.c | 2 +- src/settings/plugins/ifcfg-rh/writer.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/utils.c b/src/settings/plugins/ifcfg-rh/utils.c index 8318a65dae..8ec7c0a131 100644 --- a/src/settings/plugins/ifcfg-rh/utils.c +++ b/src/settings/plugins/ifcfg-rh/utils.c @@ -37,7 +37,7 @@ char * utils_single_quote_string (const char *str) { - static const char const drop_chars[] = "\r\n"; /* drop CR and LF */ + static const char *drop_chars = "\r\n"; /* drop CR and LF */ static const char escape_char = '\\'; /* escape char is backslash */ static const char quote_char = '\''; /* quote char is single quote */ size_t i, slen, j = 0; diff --git a/src/settings/plugins/ifcfg-rh/writer.c b/src/settings/plugins/ifcfg-rh/writer.c index 60af599bf1..acb19705c1 100644 --- a/src/settings/plugins/ifcfg-rh/writer.c +++ b/src/settings/plugins/ifcfg-rh/writer.c @@ -2502,7 +2502,6 @@ error: static char * escape_id (const char *id) { - static const char const as_dash[] = "\\][|/=()!"; char *escaped = g_strdup (id); char *p = escaped; @@ -2510,7 +2509,7 @@ escape_id (const char *id) while (*p) { if (*p == ' ') *p = '_'; - else if (strchr (as_dash, *p)) + else if (strchr ("\\][|/=()!", *p)) *p = '-'; p++; } From d93ac2c6aa0527de0a667a9031521b7ac8b019b5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 26 Jul 2014 23:09:23 +0200 Subject: [PATCH 15/21] platform/test: fix warnings in test clang warns: make[5]: Entering directory `./NetworkManager/src/platform/tests' CC test_link_fake-test-link.o test-link.c:133:1: error: control may reach end of non-void function [-Werror,-Wreturn-type] } ^ test-link.c:191:10: error: declaration shadows a variable in the global scope [-Werror,-Wshadow] char *stdout = NULL; ^ /usr/include/stdio.h:173:16: note: expanded from macro 'stdout' #define stdout stdout ^ /usr/include/stdio.h:169:25: note: previous declaration is here extern struct _IO_FILE *stdout; /* Standard output stream. */ ^ Signed-off-by: Thomas Haller (cherry picked from commit 9c9312b80553fce5339e52a7ed18e13682344222) --- src/platform/tests/test-link.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/platform/tests/test-link.c b/src/platform/tests/test-link.c index a3f757c2e7..37ba8f4ac8 100644 --- a/src/platform/tests/test-link.c +++ b/src/platform/tests/test-link.c @@ -130,6 +130,7 @@ software_add (NMLinkType link_type, const char *name) default: g_error ("Link type %d unhandled.", link_type); } + g_assert_not_reached (); } static void @@ -188,12 +189,12 @@ test_slave (int master, int type, SignalData *master_changed) /* Older team versions (e.g. Fedora 17) have a bug that team master stays * IFF_LOWER_UP even if its slave is down. Double check it with iproute2 and if * `ip link` also claims master to be up, accept it. */ - char *stdout = NULL; + char *stdout_str = NULL; - nmtst_spawn_sync (NULL, &stdout, NULL, 0, "/sbin/ip", "link", "show", "dev", nm_platform_link_get_name (master)); + nmtst_spawn_sync (NULL, &stdout_str, NULL, 0, "/sbin/ip", "link", "show", "dev", nm_platform_link_get_name (master)); - g_assert (strstr (stdout, "LOWER_UP")); - g_free (stdout); + g_assert (strstr (stdout_str, "LOWER_UP")); + g_free (stdout_str); } else g_assert_not_reached (); } From 0f6ab40a06ae91919366463119bc3b632c1cc550 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 26 Jul 2014 23:37:19 +0200 Subject: [PATCH 16/21] cli: remove unused static struct nmc_mobile_settings clang warns: make[4]: Entering directory `./NetworkManager/cli/src' CC connections.o connections.c:2206:23: error: unused variable 'nmc_mobile_settings' [-Werror,-Wunused-const-variable] static const NameItem nmc_mobile_settings [] = { ^ Signed-off-by: Thomas Haller (cherry picked from commit 996b31ec20988eed92399f6495c13dd92c38076b) --- cli/src/connections.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/cli/src/connections.c b/cli/src/connections.c index d17f7f1264..3e48586d89 100644 --- a/cli/src/connections.c +++ b/cli/src/connections.c @@ -2203,17 +2203,6 @@ static const NameItem nmc_cdma_settings [] = { { NULL, NULL, NULL, FALSE } }; -static const NameItem nmc_mobile_settings [] = { - { NM_SETTING_CONNECTION_SETTING_NAME, NULL, NULL, TRUE }, - { NM_SETTING_SERIAL_SETTING_NAME, NULL, NULL, FALSE }, - { NM_SETTING_PPP_SETTING_NAME, NULL, NULL, FALSE }, - { NM_SETTING_GSM_SETTING_NAME, NULL, NULL, TRUE }, - { NM_SETTING_CDMA_SETTING_NAME, NULL, NULL, TRUE }, - { NM_SETTING_IP4_CONFIG_SETTING_NAME, NULL, NULL, FALSE }, - { NM_SETTING_IP6_CONFIG_SETTING_NAME, NULL, NULL, FALSE }, - { NULL, NULL, NULL, FALSE } -}; - static const NameItem nmc_bluetooth_settings [] = { { NM_SETTING_CONNECTION_SETTING_NAME, NULL, NULL, TRUE }, { NM_SETTING_BLUETOOTH_SETTING_NAME, NULL, NULL, TRUE }, From 970552b56889ba6a37735b93f8c4a9f033336924 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 27 Jul 2014 02:35:17 +0200 Subject: [PATCH 17/21] platform/test: fix warning about uninitialized value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gcc warns: make[5]: Entering directory `./NetworkManager/src/platform/tests' CC platform.o platform.c: In function ‘do_ip6_route_add’: platform.c:696:2: error: ‘plen’ may be used uninitialized in this function [-Werror=maybe-uninitialized] return nm_platform_ip6_route_add (ifindex, NM_PLATFORM_SOURCE_USER, ^ platform.c: In function ‘do_ip6_route_delete’: platform.c:724:2: error: ‘plen’ may be used uninitialized in this function [-Werror=maybe-uninitialized] return nm_platform_ip6_route_delete (ifindex, network, plen, metric); ^ platform.c: In function ‘do_ip4_route_delete’: [...] Signed-off-by: Thomas Haller (cherry picked from commit f808c3603a02a4e63ce86d7d86e8724ec33e7865) --- src/platform/tests/platform.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/platform/tests/platform.c b/src/platform/tests/platform.c index ea8bd0e3b3..f505c2d26a 100644 --- a/src/platform/tests/platform.c +++ b/src/platform/tests/platform.c @@ -532,6 +532,9 @@ parse_ip_address (int family, char *str, gpointer address, int *plen) { char *endptr; + if (plen) + *plen = 0; + if (plen) { char *ptr = strchr (str, '/'); if (ptr) { From 5524f93ff8137b47d9d16d3a87018f3e541ab7a5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 27 Jul 2014 02:44:52 +0200 Subject: [PATCH 18/21] cli: fix warning about uninitialized value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gcc warns: make[4]: Entering directory `./NetworkManager/cli/src' CC connections.o connections.c: In function ‘complete_connection_by_type’: connections.c:4235:18: error: ‘mtu_int’ may be used uninitialized in this function [-Werror=maybe-uninitialized] g_object_set (s_wired, NM_SETTING_WIRED_MTU, mtu_int, NULL); ^ Signed-off-by: Thomas Haller (cherry picked from commit f0d40201aecf94e77312e0813a25b93faae093f6) --- cli/src/connections.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cli/src/connections.c b/cli/src/connections.c index 3e48586d89..b758ad5773 100644 --- a/cli/src/connections.c +++ b/cli/src/connections.c @@ -2518,6 +2518,9 @@ check_and_convert_mtu (const char *mtu, guint32 *mtu_int, GError **error) { unsigned long local_mtu_int; + if (mtu_int) + *mtu_int = 0; + if (!mtu) return TRUE; From 510bd4a9116f887b6d01c9ec57b13af60afcfe9f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 27 Jul 2014 02:20:00 +0200 Subject: [PATCH 19/21] libnm-util, core: fix warning about signed integer overflow (-Wstrict-overflow) gcc warns: make[4]: Entering directory `./NetworkManager/libnm-util' CC nm-value-transforms.lo nm-value-transforms.c: In function '_nm_utils_convert_op_array_to_string': nm-value-transforms.c:121:6: error: assuming signed overflow does not occur when simplifying conditional to constant [-Werror=strict-overflow] if (i > 0) ^ nm-value-transforms.c: In function '_nm_utils_convert_string_array_to_string': nm-value-transforms.c:121:6: error: assuming signed overflow does not occur when simplifying conditional to constant [-Werror=strict-overflow] if (i > 0) ^ make[7]: Entering directory `./NetworkManager/src/settings/plugins/ifcfg-rh' CC reader.lo reader.c: In function 'make_wired_setting': reader.c:3295:6: error: assuming signed overflow does not occur when simplifying conditional to constant [-Werror=strict-overflow] if (!found) ^ reader.c: In function 'wireless_connection_from_ifcfg': reader.c:3295:6: error: assuming signed overflow does not occur when simplifying conditional to constant [-Werror=strict-overflow] if (!found) ^ Signed-off-by: Thomas Haller (cherry picked from commit b8351111291cf305cd871f32a591c498fa748556) --- libnm-util/nm-value-transforms.c | 2 +- src/settings/plugins/ifcfg-rh/reader.c | 3 ++- src/settings/plugins/ifnet/connection_parser.c | 3 ++- src/tests/test-general.c | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/libnm-util/nm-value-transforms.c b/libnm-util/nm-value-transforms.c index f92596dc60..18c2012eaf 100644 --- a/libnm-util/nm-value-transforms.c +++ b/libnm-util/nm-value-transforms.c @@ -115,7 +115,7 @@ static void _string_array_to_string (const GPtrArray *strings, GValue *dest_value) { GString *printable; - int i; + guint i; printable = g_string_new (NULL); for (i = 0; strings && i < strings->len; i++) { diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c index 7a616707e1..0a8b521a19 100644 --- a/src/settings/plugins/ifcfg-rh/reader.c +++ b/src/settings/plugins/ifcfg-rh/reader.c @@ -3266,7 +3266,7 @@ fill_8021x (shvarFile *ifcfg, char *lower = NULL; lower = g_ascii_strdown (*iter, -1); - while (eap->method && !found) { + while (eap->method) { if (strcmp (eap->method, lower)) goto next; @@ -3287,6 +3287,7 @@ fill_8021x (shvarFile *ifcfg, } nm_setting_802_1x_add_eap_method (s_8021x, lower); found = TRUE; + break; next: eap++; diff --git a/src/settings/plugins/ifnet/connection_parser.c b/src/settings/plugins/ifnet/connection_parser.c index 85873d5f7b..32fccfc76d 100644 --- a/src/settings/plugins/ifnet/connection_parser.c +++ b/src/settings/plugins/ifnet/connection_parser.c @@ -1383,7 +1383,7 @@ fill_8021x (const char *ssid, char *lower = NULL; lower = g_ascii_strdown (*iter, -1); - while (eap->method && !found) { + while (eap->method) { if (strcmp (eap->method, lower)) goto next; @@ -1404,6 +1404,7 @@ fill_8021x (const char *ssid, } nm_setting_802_1x_add_eap_method (s_8021x, lower); found = TRUE; + break; next: eap++; diff --git a/src/tests/test-general.c b/src/tests/test-general.c index 11c03f0dbe..f3fea2bca8 100644 --- a/src/tests/test-general.c +++ b/src/tests/test-general.c @@ -66,7 +66,7 @@ test_nm_utils_ascii_str_to_int64_do (const char *str, guint base, gint64 min, NULL, }; const char **ws_pre, **ws_post, **null; - int i; + guint i; if (str == NULL || exp_errno != 0) { test_nm_utils_ascii_str_to_int64_check (str, base, min, max, fallback, exp_errno, exp_val); From e6767f3ee10bf7f9f32a6ea26b37b347b82c6026 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 27 Jul 2014 02:49:40 +0200 Subject: [PATCH 20/21] cli: fix warning in parse_output_fields() about strict-overflow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gcc warns: make[4]: Entering directory `./NetworkManager/cli/src' CC utils.o utils.c: In function ‘parse_output_fields’: utils.c:707:7: error: assuming signed overflow does not occur when simplifying conditional to constant [-Werror=strict-overflow] if (found) { ^ Signed-off-by: Thomas Haller (cherry picked from commit ef242731048406e84fa89719ef882ad154c940ea) --- cli/src/utils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/src/utils.c b/cli/src/utils.c index 9b513f5a08..d6f804ca49 100644 --- a/cli/src/utils.c +++ b/cli/src/utils.c @@ -700,9 +700,9 @@ parse_output_fields (const char *fields_str, break; } } + if (found) + break; } - if (found) - break; } if (found) { /* Add index to array, and field name (or NULL) to group_fields array */ From 8f2fa5fa804244af61faeb617a22248cc149edbf Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 29 Jul 2014 20:22:28 +0200 Subject: [PATCH 21/21] dns: fix compiler warning by refactoring use of inet_ntop Use nm_utils_inet4_ntop() and nm_utils_inet6_ntop() instead. And get rid of the unneeded error-checking. gcc warns: make[4]: Entering directory `/data/src/NetworkManager/src' CC nm-dns-manager.lo dns-manager/nm-dns-manager.c: In function 'merge_one_ip4_config': dns-manager/nm-dns-manager.c:137:37: warning: ordered comparison of pointer with integer zero [-Wextra] if (inet_ntop (AF_INET, &addr, buf, INET_ADDRSTRLEN) > 0) ^ dns-manager/nm-dns-manager.c:168:37: warning: ordered comparison of pointer with integer zero [-Wextra] if (inet_ntop (AF_INET, &addr, buf, INET_ADDRSTRLEN) > 0) ^ dns-manager/nm-dns-manager.c: In function 'merge_one_ip6_config': dns-manager/nm-dns-manager.c:197:64: warning: ordered comparison of pointer with integer zero [-Wextra] if (inet_ntop (AF_INET, &(addr->s6_addr32[3]), buf, INET_ADDRSTRLEN) > 0) ^ dns-manager/nm-dns-manager.c:200:38: warning: ordered comparison of pointer with integer zero [-Wextra] if (inet_ntop (AF_INET6, addr, buf, INET6_ADDRSTRLEN) > 0) { ^ Signed-off-by: Thomas Haller (cherry picked from commit 7580cfef20386da22f9c3d8bd20b2ab8fd954a05) (cherry picked from commit d005c77213fac8dc2635a5b4e30e2999c0126a45) --- src/dns-manager/nm-dns-manager.c | 39 ++++++++++++-------------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/src/dns-manager/nm-dns-manager.c b/src/dns-manager/nm-dns-manager.c index a1552ac246..e68906f38d 100644 --- a/src/dns-manager/nm-dns-manager.c +++ b/src/dns-manager/nm-dns-manager.c @@ -35,6 +35,7 @@ #include #include +#include "nm-utils.h" #include "nm-dns-manager.h" #include "nm-ip4-config.h" #include "nm-ip6-config.h" @@ -130,12 +131,8 @@ merge_one_ip4_config (NMResolvConfData *rc, NMIP4Config *src) num = nm_ip4_config_get_num_nameservers (src); for (i = 0; i < num; i++) { - guint32 addr; - char buf[INET_ADDRSTRLEN]; - - addr = nm_ip4_config_get_nameserver (src, i); - if (inet_ntop (AF_INET, &addr, buf, INET_ADDRSTRLEN) > 0) - add_string_item (rc->nameservers, buf); + add_string_item (rc->nameservers, + nm_utils_inet4_ntop (nm_ip4_config_get_nameserver (src, i), NULL)); } num = nm_ip4_config_get_num_domains (src); @@ -161,12 +158,8 @@ merge_one_ip4_config (NMResolvConfData *rc, NMIP4Config *src) /* NIS stuff */ num = nm_ip4_config_get_num_nis_servers (src); for (i = 0; i < num; i++) { - guint32 addr; - char buf[INET_ADDRSTRLEN]; - - addr = nm_ip4_config_get_nis_server (src, i); - if (inet_ntop (AF_INET, &addr, buf, INET_ADDRSTRLEN) > 0) - add_string_item (rc->nis_servers, buf); + add_string_item (rc->nis_servers, + nm_utils_inet4_ntop (nm_ip4_config_get_nis_server (src, i), NULL)); } if (nm_ip4_config_get_nis_domain (src)) { @@ -187,25 +180,21 @@ merge_one_ip6_config (NMResolvConfData *rc, NMIP6Config *src) num = nm_ip6_config_get_num_nameservers (src); for (i = 0; i < num; i++) { const struct in6_addr *addr; - char buf[INET6_ADDRSTRLEN]; - char *tmp; + char buf[NM_UTILS_INET_ADDRSTRLEN + 50]; addr = nm_ip6_config_get_nameserver (src, i); /* inet_ntop is probably supposed to do this for us, but it doesn't */ - if (IN6_IS_ADDR_V4MAPPED (addr)) { - if (inet_ntop (AF_INET, &(addr->s6_addr32[3]), buf, INET_ADDRSTRLEN) > 0) - add_string_item (rc->nameservers, buf); - } else { - if (inet_ntop (AF_INET6, addr, buf, INET6_ADDRSTRLEN) > 0) { - if (iface && IN6_IS_ADDR_LINKLOCAL (addr)) { - tmp = g_strdup_printf ("%s%%%s", buf, iface); - add_string_item (rc->nameservers, tmp); - g_free (tmp); - } else - add_string_item (rc->nameservers, buf); + if (IN6_IS_ADDR_V4MAPPED (addr)) + nm_utils_inet4_ntop (addr->s6_addr32[3], buf); + else { + nm_utils_inet6_ntop (addr, buf); + if (iface && IN6_IS_ADDR_LINKLOCAL (addr)) { + g_strlcat (buf, "%", sizeof (buf)); + g_strlcat (buf, iface, sizeof (buf)); } } + add_string_item (rc->nameservers, buf); } num = nm_ip6_config_get_num_domains (src);