diff --git a/examples/dispatcher/10-ifcfg-rh-routes.sh b/examples/dispatcher/10-ifcfg-rh-routes.sh index 147506e471..d72400aed7 100755 --- a/examples/dispatcher/10-ifcfg-rh-routes.sh +++ b/examples/dispatcher/10-ifcfg-rh-routes.sh @@ -45,7 +45,7 @@ handle_ip_file() { } -if [ "$2" != "pre-up" -a "$2" != "down" ]; then +if [ "$2" != "pre-up" ] && [ "$2" != "down" ]; then exit 0 fi @@ -59,7 +59,7 @@ if [ -z "$profile" ]; then exit 0 fi -if ! [ -f "$dir/rule-$profile" -o -f "$dir/rule6-$profile" ]; then +if [ ! -f "$dir/rule-$profile" ] && [ ! -f "$dir/rule6-$profile" ]; then exit 0 fi diff --git a/libnm-core/nm-setting-ip-config.c b/libnm-core/nm-setting-ip-config.c index fa2535b8f0..2b3134b666 100644 --- a/libnm-core/nm-setting-ip-config.c +++ b/libnm-core/nm-setting-ip-config.c @@ -1310,7 +1310,7 @@ nm_ip_route_attribute_validate (const char *name, return FALSE; } - if (spec->type == G_VARIANT_TYPE_STRING) { + if (g_variant_type_equal (spec->type, G_VARIANT_TYPE_STRING)) { const char *string = g_variant_get_string (value, NULL); gs_free char *string_free = NULL; char *sep; diff --git a/libnm-core/nm-setting-sriov.c b/libnm-core/nm-setting-sriov.c index 45b3a1d2f5..7228fb0cc2 100644 --- a/libnm-core/nm-setting-sriov.c +++ b/libnm-core/nm-setting-sriov.c @@ -433,7 +433,7 @@ nm_sriov_vf_attribute_validate (const char *name, return FALSE; } - if (spec->type == G_VARIANT_TYPE_STRING) { + if (g_variant_type_equal (spec->type, G_VARIANT_TYPE_STRING)) { const char *string; switch (spec->str_type) { diff --git a/libnm-core/nm-setting-team.c b/libnm-core/nm-setting-team.c index e6737e48ce..e311ba7776 100644 --- a/libnm-core/nm-setting-team.c +++ b/libnm-core/nm-setting-team.c @@ -125,9 +125,9 @@ nm_team_link_watcher_new_ethtool (int delay_up, NMTeamLinkWatcher *watcher; const char *val_fail = NULL; - if (delay_up < 0 || delay_up > G_MAXINT32) + if (delay_up < 0 || !_NM_INT_LE_MAXINT32 (delay_up)) val_fail = "delay-up"; - if (delay_down < 0 || delay_down > G_MAXINT32) + if (delay_down < 0 || !_NM_INT_LE_MAXINT32 (delay_up)) val_fail = "delay-down"; if (val_fail) { g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_FAILED, diff --git a/libnm-core/nm-setting.c b/libnm-core/nm-setting.c index 0cec516517..fa0125b965 100644 --- a/libnm-core/nm-setting.c +++ b/libnm-core/nm-setting.c @@ -1422,7 +1422,7 @@ nm_setting_diff (NMSetting *a, } else { g_hash_table_iter_init (&iter, a_gendata->hash); while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *) &val)) { - val2 = b_gendata ? g_hash_table_lookup (b_gendata->hash, key) : NULL; + val2 = g_hash_table_lookup (b_gendata->hash, key); compared_any = TRUE; if ( !val2 || !g_variant_equal (val, val2)) { @@ -1432,7 +1432,7 @@ nm_setting_diff (NMSetting *a, } g_hash_table_iter_init (&iter, b_gendata->hash); while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *) &val)) { - val2 = a_gendata ? g_hash_table_lookup (a_gendata->hash, key) : NULL; + val2 = g_hash_table_lookup (a_gendata->hash, key); compared_any = TRUE; if ( !val2 || !g_variant_equal (val, val2)) { diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index f6e1555ef8..0f524e11be 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -4941,18 +4941,18 @@ const char **nm_utils_enum_get_values (GType type, int from, int to) static gboolean _nm_utils_is_json_object_no_validation (const char *str, GError **error) { - if (str) { - /* libjansson also requires only utf-8 encoding. */ - if (!g_utf8_validate (str, -1, NULL)) { - g_set_error_literal (error, - NM_CONNECTION_ERROR, - NM_CONNECTION_ERROR_INVALID_PROPERTY, - _("not valid utf-8")); - return FALSE; - } - while (g_ascii_isspace (str[0])) - str++; + nm_assert (str); + + /* libjansson also requires only utf-8 encoding. */ + if (!g_utf8_validate (str, -1, NULL)) { + g_set_error_literal (error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_INVALID_PROPERTY, + _("not valid utf-8")); + return FALSE; } + while (g_ascii_isspace (str[0])) + str++; /* do some very basic validation to see if this might be a JSON object. */ if (str[0] == '{') { diff --git a/shared/nm-utils/nm-shared-utils.c b/shared/nm-utils/nm-shared-utils.c index 022c065283..4c2e329797 100644 --- a/shared/nm-utils/nm-shared-utils.c +++ b/shared/nm-utils/nm-shared-utils.c @@ -1236,7 +1236,7 @@ nm_utils_buf_utf8safe_unescape (const char *str, gsize *out_len, gpointer *to_fr ch = (++str)[0]; if (ch >= '0' && ch <= '7') { v = v * 8 + (ch - '0'); - ch = (++str)[0]; + ++str; } } ch = v; diff --git a/shared/nm-utils/nm-shared-utils.h b/shared/nm-utils/nm-shared-utils.h index 5125bd3d85..bc492571a8 100644 --- a/shared/nm-utils/nm-shared-utils.h +++ b/shared/nm-utils/nm-shared-utils.h @@ -34,7 +34,7 @@ _NM_INT_NOT_NEGATIVE (gssize val) * * When using such an enum for accessing an array, one naturally wants to check * that the enum is not negative. However, the compiler doesn't like a plain - * comparisong "enum_val >= 0", because (if the enum is unsigned), it will warn + * comparison "enum_val >= 0", because (if the enum is unsigned), it will warn * that the expression is always true *duh*. Not even a cast to a signed * type helps to avoid the compiler warning in any case. * @@ -43,6 +43,33 @@ _NM_INT_NOT_NEGATIVE (gssize val) return val >= 0; } +/* check whether the integer value is smaller than G_MAXINT32. This macro exists + * for the sole purpose, that a plain "((int) value <= G_MAXINT32)" comparison + * may cause the compiler or coverity that this check is always TRUE. But the + * check depends on compile time and the size of C type "int". Of course, most + * of the time in is gint32 and an int value is always <= G_MAXINT32. The check + * exists to catch cases where that is not true. + * + * Together with the G_STATIC_ASSERT(), we make sure that this is always satisfied. */ +G_STATIC_ASSERT (sizeof (int) == sizeof (gint32)); +#if _NM_CC_SUPPORT_GENERIC +#define _NM_INT_LE_MAXINT32(value) \ + ({ \ + _nm_unused typeof (value) _value = (value); \ + \ + _Generic((value), \ + int: TRUE \ + ); \ + }) +#else +#define _NM_INT_LE_MAXINT32(value) ({ \ + _nm_unused typeof (value) _value = (value); \ + _nm_unused const int *_p_value = &_value; \ + \ + TRUE; \ + }) +#endif + /*****************************************************************************/ static inline char diff --git a/src/devices/nm-device-ethernet-utils.c b/src/devices/nm-device-ethernet-utils.c index 8bdb19917a..b18eadfa9b 100644 --- a/src/devices/nm-device-ethernet-utils.c +++ b/src/devices/nm-device-ethernet-utils.c @@ -29,7 +29,7 @@ nm_device_ethernet_utils_get_default_wired_name (GHashTable *existing_ids) int i; /* Find the next available unique connection name */ - for (i = 1; i <= G_MAXINT; i++) { + for (i = 1; i < G_MAXINT; i++) { temp = g_strdup_printf (_("Wired connection %d"), i); if ( !existing_ids || !g_hash_table_contains (existing_ids, temp))