summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-03-23 17:25:04 +0100
committerThomas Haller <thaller@redhat.com>2017-03-23 18:04:13 +0100
commite4c0a4d0f22e1135173032d221d6c2756cf1da3f (patch)
tree9de4a35972761664f91eb43be5362df40e421eab
parentb3f6bf3daf3ca6df70ac47c6fd68b6ec092d9e9a (diff)
downloadNetworkManager-e4c0a4d0f22e1135173032d221d6c2756cf1da3f.tar.gz
shared: minor change to NM_FLAGS_HAS() and nm_utils_is_power_of_two() macros
NM_FLAGS_HAS() should reject negative flag values. So check for > 0. Also change parentheses and line wrap.
-rw-r--r--shared/nm-utils/nm-macros-internal.h10
1 files changed, 5 insertions, 5 deletions
diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h
index 3147f58c2b..e1e3431a75 100644
--- a/shared/nm-utils/nm-macros-internal.h
+++ b/shared/nm-utils/nm-macros-internal.h
@@ -610,16 +610,16 @@ nm_clear_g_cancellable (GCancellable **cancellable)
/* Determine whether @x is a power of two (@x being an integer type).
* For the special cases @x equals zero or one, it also returns true.
- * For negative @x, always returns FALSE. That only applies, if the data
- * type of @x is signed. */
+ * In case @x being a signed type, for negative @x always return FALSE. */
#define nm_utils_is_power_of_two(x) ({ \
typeof(x) __x = (x); \
\
/* Check if the value is negative. In that case, return FALSE.
* The first expression is a compile time constant, depending on whether
* the type is signed. The second expression is a clumsy way for (__x >= 0),
- * which causes a compiler warning for unsigned types. */ \
- ( ( ((typeof(__x)) -1) > ((typeof(__x)) 0) ) || (__x > 0) || (__x == 0) ) \
+ * which otherwise causes a compiler warning for unsigned types. */ \
+ ( (((typeof(__x)) -1) > ((typeof(__x)) 0)) \
+ || (__x > 0 || __x == 0) ) \
&& ((__x & (__x - 1)) == 0); \
})
@@ -628,7 +628,7 @@ nm_clear_g_cancellable (GCancellable **cancellable)
/* check if @flags has exactly one flag (@check) set. You should call this
* only with @check being a compile time constant and a power of two. */
#define NM_FLAGS_HAS(flags, check) \
- ( (G_STATIC_ASSERT_EXPR ( ((check) != 0) && ((check) & ((check)-1)) == 0 )), (NM_FLAGS_ANY ((flags), (check))) )
+ ( G_STATIC_ASSERT_EXPR ((check) > 0 && ((check) & ((check) - 1)) == 0), NM_FLAGS_ANY ((flags), (check)) )
#define NM_FLAGS_ANY(flags, check) ( ( ((flags) & (check)) != 0 ) ? TRUE : FALSE )
#define NM_FLAGS_ALL(flags, check) ( ( ((flags) & (check)) == (check) ) ? TRUE : FALSE )