From 3ce2dd49591d83ab0a20d6f8b47436fb194fdd61 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 7 Apr 2021 14:31:16 +0200 Subject: [PATCH] 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. --- src/libnm-glib-aux/nm-macros-internal.h | 10 ++++++++-- 1 file 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) \ ({ \