From 6f4a60b6f2eee9c5c2d983d46b827da38ee2f66d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 27 Oct 2023 14:27:01 +0200 Subject: [PATCH] all: ensure same signedness of arguments to MIN()/MAX() Comparing integers of different signedness gives often unexpected results. Adjust usages of MIN()/MAX() to ensure that the arguments agree in signedness. --- src/core/devices/wifi/nm-iwd-manager.c | 2 +- src/core/nm-connectivity.c | 2 +- src/core/nm-core-utils.c | 12 ++++++------ src/core/supplicant/nm-supplicant-interface.c | 2 +- src/core/tests/test-core-with-expect.c | 2 +- src/libnm-platform/wifi/nm-wifi-utils-wext.c | 2 +- src/libnmt-newt/nmt-newt-form.c | 4 ++-- src/nmcli/devices.c | 2 +- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/core/devices/wifi/nm-iwd-manager.c b/src/core/devices/wifi/nm-iwd-manager.c index 3db52d4b6f..9f06b9fdb3 100644 --- a/src/core/devices/wifi/nm-iwd-manager.c +++ b/src/core/devices/wifi/nm-iwd-manager.c @@ -1902,7 +1902,7 @@ nm_iwd_manager_get_ap_mirror_connection(NMIwdManager *self, NMWifiAP *ap) NM80211ApSecurityFlags sec_flags = nm_wifi_ap_get_wpa_flags(ap) | nm_wifi_ap_get_rsn_flags(ap); ssid_bytes = g_bytes_get_data(nm_wifi_ap_get_ssid(ap), &ssid_len); - ssid_len = MIN(ssid_len, 32); + ssid_len = MIN(ssid_len, 32u); memcpy(name_buf, ssid_bytes, ssid_len); name_buf[ssid_len] = '\0'; diff --git a/src/core/nm-connectivity.c b/src/core/nm-connectivity.c index 76223cf121..bb1a7baee8 100644 --- a/src/core/nm-connectivity.c +++ b/src/core/nm-connectivity.c @@ -1295,7 +1295,7 @@ update_config(NMConnectivity *self, NMConfigData *config_data) priv->uri_valid = new_uri_valid; interval = nm_config_data_get_connectivity_interval(config_data); - interval = MIN(interval, (7 * 24 * 3600)); + interval = MIN(interval, (7u * 24 * 3600)); if (priv->interval != interval) { priv->interval = interval; changed = TRUE; diff --git a/src/core/nm-core-utils.c b/src/core/nm-core-utils.c index a6c20ad851..1f43463491 100644 --- a/src/core/nm-core-utils.c +++ b/src/core/nm-core-utils.c @@ -738,15 +738,15 @@ nm_utils_kill_child_sync(pid_t pid, if (!was_waiting) { nm_log_dbg(log_domain, - LOG_NAME_FMT ": waiting up to %ld milliseconds for process to terminate " + LOG_NAME_FMT ": waiting up to %lu milliseconds for process to terminate " "normally after sending %s...", LOG_NAME_ARGS, - (long) MAX(wait_before_kill_msec, 0), + (unsigned long) wait_before_kill_msec, _kc_signal_to_string(sig)); was_waiting = TRUE; } - sleep_time = MIN(wait_until - now, sleep_duration_usec); + sleep_time = MIN(wait_until - now, (gint64) sleep_duration_usec); if (loop_count < 20) { /* At the beginning we expect the process to die fast. * Limit the sleep time, the limit doubles with every iteration. */ @@ -1031,17 +1031,17 @@ nm_utils_kill_process_sync(pid_t pid, loop_count = 0; /* reset the loop_count. Now we really expect the process to die quickly. */ } else - sleep_time = MIN(wait_until_sigkill - now, sleep_duration_usec); + sleep_time = MIN(wait_until_sigkill - now, (gint64) sleep_duration_usec); } if (!was_waiting) { if (wait_until_sigkill != 0) { nm_log_dbg(log_domain, LOG_NAME_PROCESS_FMT - ": waiting up to %ld milliseconds for process to disappear before " + ": waiting up to %lu milliseconds for process to disappear before " "sending KILL signal after sending %s...", LOG_NAME_ARGS, - (long) wait_before_kill_msec, + (unsigned long) wait_before_kill_msec, _kc_signal_to_string(sig)); } else if (max_wait_until != 0) { nm_log_dbg( diff --git a/src/core/supplicant/nm-supplicant-interface.c b/src/core/supplicant/nm-supplicant-interface.c index e7bdfd49df..a867785100 100644 --- a/src/core/supplicant/nm-supplicant-interface.c +++ b/src/core/supplicant/nm-supplicant-interface.c @@ -689,7 +689,7 @@ _bss_info_properties_changed(NMSupplicantInterface *self, v_v = nm_g_variant_lookup_value(properties, "SSID", G_VARIANT_TYPE_BYTESTRING); if (v_v) { arr_data = g_variant_get_fixed_array(v_v, &arr_len, 1); - arr_len = MIN(32, arr_len); + arr_len = MIN(32u, arr_len); /* Stupid ieee80211 layer uses */ if (arr_data && arr_len diff --git a/src/core/tests/test-core-with-expect.c b/src/core/tests/test-core-with-expect.c index 015101262c..54206d814a 100644 --- a/src/core/tests/test-core-with-expect.c +++ b/src/core/tests/test-core-with-expect.c @@ -617,7 +617,7 @@ test_nmp_utils_new_vlan_name(void) g_assert(ifname && ifname[0]); g_assert_cmpint(strlen(ifname), ==, - MIN(15, strlen(parent_names[i]) + strlen(vlan_id_s))); + MIN(15u, strlen(parent_names[i]) + strlen(vlan_id_s))); g_assert(g_str_has_suffix(ifname, vlan_id_s)); g_assert(ifname[strlen(ifname) - strlen(vlan_id_s)] == '.'); g_assert(strncmp(ifname, parent_names[i], strlen(ifname) - strlen(vlan_id_s)) == 0); diff --git a/src/libnm-platform/wifi/nm-wifi-utils-wext.c b/src/libnm-platform/wifi/nm-wifi-utils-wext.c index 8ebf6bef80..5174958c37 100644 --- a/src/libnm-platform/wifi/nm-wifi-utils-wext.c +++ b/src/libnm-platform/wifi/nm-wifi-utils-wext.c @@ -758,7 +758,7 @@ nm_wifi_utils_wext_new(int ifindex, gboolean check_scan) wext->max_qual.noise = range.max_qual.noise; wext->max_qual.updated = range.max_qual.updated; - wext->num_freqs = MIN(range.num_frequency, IW_MAX_FREQUENCIES); + wext->num_freqs = MIN(range.num_frequency, (guint) IW_MAX_FREQUENCIES); for (i = 0; i < wext->num_freqs; i++) { wext->freqs[i] = iw_freq_to_uint32(&range.freq[i]); freq_valid = TRUE; diff --git a/src/libnmt-newt/nmt-newt-form.c b/src/libnmt-newt/nmt-newt-form.c index 6e0589cc5b..91b2a8c260 100644 --- a/src/libnmt-newt/nmt-newt-form.c +++ b/src/libnmt-newt/nmt-newt-form.c @@ -182,9 +182,9 @@ nmt_newt_form_build(NmtNewtForm *form) newtGetScreenSize(&screen_width, &screen_height); if (!priv->fixed_width) - priv->width = MIN(form_width + 2 * priv->padding, screen_width - 2); + priv->width = MIN(form_width + 2 * ((gint64) priv->padding), screen_width - 2); if (!priv->fixed_height) - priv->height = MIN(form_height + 2 * priv->padding, screen_height - 2); + priv->height = MIN(form_height + 2 * ((gint64) priv->padding), screen_height - 2); if (!priv->fixed_x) priv->x = (screen_width - form_width) / 2; diff --git a/src/nmcli/devices.c b/src/nmcli/devices.c index a085baac62..72a0c7443a 100644 --- a/src/nmcli/devices.c +++ b/src/nmcli/devices.c @@ -1347,7 +1347,7 @@ fill_output_access_point(NMAccessPoint *ap, const APInfo *info) mode = nm_access_point_get_mode(ap); bitrate = nm_access_point_get_max_bitrate(ap); bandwidth = nm_access_point_get_bandwidth(ap); - strength = MIN(nm_access_point_get_strength(ap), 100); + strength = MIN(nm_access_point_get_strength(ap), 100u); /* Convert to strings */ if (ssid) {