summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2021-04-07 14:31:16 +0200
committerThomas Haller <thaller@redhat.com>2021-04-07 14:36:46 +0200
commit3ce2dd49591d83ab0a20d6f8b47436fb194fdd61 (patch)
tree1b7b2bfa89bd46152d5da1d7d406f0c61c37ef48
parentaf360238be198257934b89d42f24431401550721 (diff)
downloadNetworkManager-3ce2dd49591d83ab0a20d6f8b47436fb194fdd61.tar.gz
glib-aux: only evaluate arguments to NM_FLAGS_ALL() macro once
In many cases, macros should aim to be function-like. That is, to evaluate all arguments and evaluate them exactly once. Fix NM_FLAGS_ALL() to evaluate the "check" argument only once. One downside of this change is that the result is no longer a compile time constance and cannot be used to initialize static variables. But that isn't used much anyway.
-rw-r--r--src/libnm-glib-aux/nm-macros-internal.h10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/libnm-glib-aux/nm-macros-internal.h b/src/libnm-glib-aux/nm-macros-internal.h
index fb16ddc703..ac667c5881 100644
--- a/src/libnm-glib-aux/nm-macros-internal.h
+++ b/src/libnm-glib-aux/nm-macros-internal.h
@@ -1275,8 +1275,14 @@ default: \
(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)
+#define NM_FLAGS_ANY(flags, check) (((flags) & (check)) != 0)
+
+#define NM_FLAGS_ALL(flags, check) \
+ ({ \
+ const typeof(check) _check = (check); \
+ \
+ (((flags) & (_check)) == (_check)); \
+ })
#define NM_FLAGS_SET(flags, val) \
({ \