summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-05-06 23:03:10 +0200
committerThomas Haller <thaller@redhat.com>2020-05-07 13:58:09 +0200
commit9acf32a7a8035ddee027baa4fef445c7e74696e2 (patch)
tree18ab44f4cdacf7f36dbc916a3a2775945d42b470 /src
parent3a1273f777133d5be745950dce4555c2adb664f0 (diff)
downloadNetworkManager-9acf32a7a8035ddee027baa4fef445c7e74696e2.tar.gz
config: avoid lgtm.com warning about int bitfield for NMConfigDeviceStateData.nm_owned
lgtm.com warns: int nm_owned:3; >> Bit field nm_owned of type int should have explicitly unsigned integral, explicitly signed integral, or enumeration type. So make it a NMTernary instead. It's nicer anyway.
Diffstat (limited to 'src')
-rw-r--r--src/nm-config.c16
-rw-r--r--src/nm-config.h4
-rw-r--r--src/nm-manager.c6
3 files changed, 15 insertions, 11 deletions
diff --git a/src/nm-config.c b/src/nm-config.c
index 63347db7bb..9a16aa0374 100644
--- a/src/nm-config.c
+++ b/src/nm-config.c
@@ -2210,7 +2210,7 @@ _config_device_state_data_new (int ifindex, GKeyFile *kf)
gs_free char *perm_hw_addr_fake = NULL;
gsize connection_uuid_len;
gsize perm_hw_addr_fake_len;
- int nm_owned = -1;
+ NMTernary nm_owned;
char *p;
guint32 route_metric_default_effective;
guint32 route_metric_default_aspired;
@@ -2252,7 +2252,7 @@ _config_device_state_data_new (int ifindex, GKeyFile *kf)
nm_owned = nm_config_keyfile_get_boolean (kf,
DEVICE_RUN_STATE_KEYFILE_GROUP_DEVICE,
DEVICE_RUN_STATE_KEYFILE_KEY_DEVICE_NM_OWNED,
- -1);
+ NM_TERNARY_DEFAULT);
/* metric zero is not a valid metric. While zero valid for IPv4, for IPv6 it is an alias
* for 1024. Since we handle here IPv4 and IPv6 the same, we cannot allow zero. */
@@ -2325,9 +2325,11 @@ nm_config_device_state_load (int ifindex)
return NULL;
device_state = _config_device_state_data_new (ifindex, kf);
- nm_owned_str = device_state->nm_owned == TRUE ?
- ", nm-owned=1" :
- (device_state->nm_owned == FALSE ? ", nm-owned=0" : "");
+ nm_owned_str = device_state->nm_owned == NM_TERNARY_TRUE
+ ? ", nm-owned=1"
+ : ( device_state->nm_owned == NM_TERNARY_FALSE
+ ? ", nm-owned=0"
+ : "");
_LOGT ("device-state: %s #%d (%s); managed=%s%s%s%s%s%s%s%s, route-metric-default=%"G_GUINT32_FORMAT"-%"G_GUINT32_FORMAT"",
kf ? "read" : "miss",
@@ -2390,7 +2392,7 @@ nm_config_device_state_write (int ifindex,
NMConfigDeviceStateManagedType managed,
const char *perm_hw_addr_fake,
const char *connection_uuid,
- int nm_owned,
+ NMTernary nm_owned,
guint32 route_metric_default_aspired,
guint32 route_metric_default_effective,
const char *next_server,
@@ -2429,7 +2431,7 @@ nm_config_device_state_write (int ifindex,
DEVICE_RUN_STATE_KEYFILE_KEY_DEVICE_CONNECTION_UUID,
connection_uuid);
}
- if (nm_owned >= 0) {
+ if (nm_owned != NM_TERNARY_DEFAULT) {
g_key_file_set_boolean (kf,
DEVICE_RUN_STATE_KEYFILE_GROUP_DEVICE,
DEVICE_RUN_STATE_KEYFILE_KEY_DEVICE_NM_OWNED,
diff --git a/src/nm-config.h b/src/nm-config.h
index b4478ceb04..0fce7ec0cb 100644
--- a/src/nm-config.h
+++ b/src/nm-config.h
@@ -243,7 +243,7 @@ struct _NMConfigDeviceStateData {
/* whether the device was nm-owned (0/1) or -1 for
* non-software devices. */
- int nm_owned:3;
+ NMTernary nm_owned:3;
};
NMConfigDeviceStateData *nm_config_device_state_load (int ifindex);
@@ -252,7 +252,7 @@ gboolean nm_config_device_state_write (int ifindex,
NMConfigDeviceStateManagedType managed,
const char *perm_hw_addr_fake,
const char *connection_uuid,
- int nm_owned,
+ NMTernary nm_owned,
guint32 route_metric_default_aspired,
guint32 route_metric_default_effective,
const char *next_server,
diff --git a/src/nm-manager.c b/src/nm-manager.c
index bbe501259f..8cee206bef 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -6552,7 +6552,7 @@ nm_manager_write_device_state (NMManager *self, NMDevice *device, int *out_ifind
gboolean perm_hw_addr_is_fake;
guint32 route_metric_default_aspired;
guint32 route_metric_default_effective;
- int nm_owned;
+ NMTernary nm_owned;
NMDhcpConfig *dhcp_config;
const char *next_server = NULL;
const char *root_path = NULL;
@@ -6588,7 +6588,9 @@ nm_manager_write_device_state (NMManager *self, NMDevice *device, int *out_ifind
if (perm_hw_addr_fake && !perm_hw_addr_is_fake)
perm_hw_addr_fake = NULL;
- nm_owned = nm_device_is_software (device) ? nm_device_is_nm_owned (device) : -1;
+ nm_owned = nm_device_is_software (device)
+ ? nm_device_is_nm_owned (device)
+ : NM_TERNARY_DEFAULT;
route_metric_default_effective = _device_route_metric_get (self, ifindex, NM_DEVICE_TYPE_UNKNOWN,
TRUE, &route_metric_default_aspired);