]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Use SET_FLAG(subtype) rather than explicitly writing the equivalent code (#4453)
authorJames Jones <jejones3141@gmail.com>
Thu, 7 Apr 2022 20:35:51 +0000 (15:35 -0500)
committerGitHub <noreply@github.com>
Thu, 7 Apr 2022 20:35:51 +0000 (16:35 -0400)
It *may* be that the explicit version is there to avoid the compiler
kvetching about a needless bit++ at the end. If that's the case, one
can switch to initializing bit to -1 and preincrementing rather than
postincrementing.

src/lib/util/dict_validate.c

index eef34c956c3e82103703cfbbac3bfc8f3109350f..b2121a6abda09fd673a8079d20985f58e67f977e 100644 (file)
@@ -52,20 +52,16 @@ bool dict_attr_flags_valid(fr_dict_t *dict, fr_dict_attr_t const *parent,
         *      can check them in parallel.
         */
        all_flags = 0;
-       bit = 0;
+       bit = -1;
 
-#define SET_FLAG(_flag) do { shift_ ## _flag = 1 << bit; if (flags->_flag) {all_flags |= (1 << bit); } bit++; } while (0)
+#define SET_FLAG(_flag) do { shift_ ## _flag = 1 << ++bit; if (flags->_flag) all_flags |= (1 << bit); } while (0)
        SET_FLAG(is_root);
        SET_FLAG(internal);
        SET_FLAG(array);
        SET_FLAG(has_value);
        SET_FLAG(virtual);
        SET_FLAG(extra);
-
-       shift_subtype = (1 << bit);
-       if (flags->subtype) {
-               all_flags |= (1 << bit);
-       }
+       SET_FLAG(subtype);
 
 #define FORBID_OTHER_FLAGS(_flag) do { if (all_flags & ~shift_ ## _flag) { fr_strerror_printf("The '" STRINGIFY(_flag) "' flag cannot be used with any other flag"); return false; } } while (0)
 #define ALLOW_FLAG(_flag) do { all_flags &= ~shift_ ## _flag; } while (0)