all: don't use NM_FLAGS_HAS() with non-constant argument

NM_FLAGS_HAS() uses a static-assert that the second argument is a
single flag (power of two). With a single flag, NM_FLAGS_HAS(),
NM_FLAGS_ANY() and NM_FLAGS_ALL() are all identical.

The second argument must be a compile time constant, and if that is
not the case, one must not use NM_FLAGS_HAS().

Use NM_FLAGS_ANY() in these cases.
This commit is contained in:
Thomas Haller
2017-12-11 16:38:42 +01:00
parent b2273ce3dd
commit c696a226ea
7 changed files with 9 additions and 9 deletions

View File

@@ -537,7 +537,7 @@ _nm_setting_bond_option_supported (const char *option, NMBondMode mode)
for (i = 0; i < G_N_ELEMENTS (bond_unsupp_modes); i++) {
if (nm_streq (option, bond_unsupp_modes[i].option))
return !NM_FLAGS_HAS (bond_unsupp_modes[i].unsupp_modes, BIT (mode));
return !NM_FLAGS_ANY (bond_unsupp_modes[i].unsupp_modes, BIT (mode));
}
return TRUE;

View File

@@ -12246,7 +12246,7 @@ nm_device_check_connection_available (NMDevice *self,
for (i = 0; i <= NM_DEVICE_CHECK_CON_AVAILABLE_ALL; i++) {
for (j = 1; j <= NM_DEVICE_CHECK_CON_AVAILABLE_ALL; j <<= 1) {
if (NM_FLAGS_HAS (i, j)) {
if (NM_FLAGS_ANY (i, j)) {
k = i & ~j;
nm_assert ( available_all[i] == available_all[k]
|| available_all[i]);

View File

@@ -123,7 +123,7 @@ build_message (GPtrArray *fields, AuditBackend backend)
for (i = 0; i < fields->len; i++) {
field = fields->pdata[i];
if (!NM_FLAGS_HAS (field->backends, backend))
if (!NM_FLAGS_ANY (field->backends, backend))
continue;
if (first)

View File

@@ -663,7 +663,7 @@ _nm_log_impl (const char *file,
NMLogDomain dom = dom_all & _nm_logging_enabled_state[level];
for (diter = &global.domain_desc[0]; diter->name; diter++) {
if (!NM_FLAGS_HAS (dom_all, diter->num))
if (!NM_FLAGS_ANY (dom_all, diter->num))
continue;
/* construct a list of all domains (not only the enabled ones).
@@ -681,7 +681,7 @@ _nm_log_impl (const char *file,
g_string_append (s_domain_all, diter->name);
}
if (NM_FLAGS_HAS (dom, diter->num)) {
if (NM_FLAGS_ANY (dom, diter->num)) {
if (i_domain > 0) {
/* SYSLOG_FACILITY is specified multiple times for each domain that is actually enabled. */
_iovec_set_format_a (iov++, _MAX_LEN (30, diter->name), "SYSLOG_FACILITY=%s", diter->name);

View File

@@ -283,7 +283,7 @@ typedef enum {
#define FOR_EACH_DELAYED_ACTION(iflags, flags_all) \
for ((iflags) = (DelayedActionType) 0x1LL; (iflags) <= DELAYED_ACTION_TYPE_MAX; (iflags) <<= 1) \
if (NM_FLAGS_HAS (flags_all, iflags))
if (NM_FLAGS_ANY (flags_all, iflags))
typedef enum {
/* Negative values are errors from kernel. Add dummy member to

View File

@@ -200,8 +200,8 @@ _stack_current_ns_types (NMPNetns *netns, int ns_types)
}
for (i = 0; i < G_N_ELEMENTS (ns_types_check); i++) {
if ( NM_FLAGS_HAS (ns_types, ns_types_check[i])
&& NM_FLAGS_HAS (info->ns_types, ns_types_check[i])) {
if ( NM_FLAGS_ANY (ns_types, ns_types_check[i])
&& NM_FLAGS_ANY (info->ns_types, ns_types_check[i])) {
res = NM_FLAGS_SET (res, ns_types_check[i]);
ns_types = NM_FLAGS_UNSET (ns_types, ns_types_check[i]);
}

View File

@@ -2230,7 +2230,7 @@ test_netns_push (gpointer fixture, gconstpointer test_data)
p = pl_base;
for (j = nstack; j >= 1; ) {
j--;
if (NM_FLAGS_HAS (stack[j].ns_types, ns_type)) {
if (NM_FLAGS_ANY (stack[j].ns_types, ns_type)) {
p = stack[j].pl;
break;
}