From: Alan T. DeKok Date: Mon, 16 Mar 2026 21:47:10 +0000 (-0400) Subject: define MEMCMP_FIELDS() and use it X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a0027ee4eeee622243d304abf85cfee9cbabe51d;p=thirdparty%2Ffreeradius-server.git define MEMCMP_FIELDS() and use it which is a little clearer (and less wrappers) than MEMCMP_RETURN --- diff --git a/src/include/build.h b/src/include/build.h index eb47d0fdded..265838d0814 100644 --- a/src/include/build.h +++ b/src/include/build.h @@ -160,6 +160,17 @@ do { \ if (_ret != 0) return _ret; \ } while (0) +/** Return the comparison of two opaque fields of a structure + * + * @param[in] _a pointer to first structure. + * @param[in] _b pointer to second structure. + * @param[in] _field within the structs to compare. + * @param[in] _len_field within the structs, specifying the length of the data. + * @return The result of the comparison. + */ +#define MEMCMP_FIELDS(_a, _b, _field, _len_field) \ + memcmp_return((_a)->_field, (_b)->_field, (_a)->_len_field, (_b)->_len_field) + /** Remove const qualification from a pointer * * @param[in] _type The non-const version of the type. diff --git a/src/lib/server/map_proc.c b/src/lib/server/map_proc.c index 2826ce6758e..6ea897d3e30 100644 --- a/src/lib/server/map_proc.c +++ b/src/lib/server/map_proc.c @@ -40,8 +40,7 @@ static int8_t map_proc_cmp(void const *one, void const *two) { map_proc_t const *a = one, *b = two; - MEMCMP_RETURN(a, b, name, length); - return 0; + return MEMCMP_FIELDS(a, b, name, length); } /** Unregister a map processor diff --git a/src/lib/util/sbuff.c b/src/lib/util/sbuff.c index 35ef37812c3..90fcdaa5992 100644 --- a/src/lib/util/sbuff.c +++ b/src/lib/util/sbuff.c @@ -633,8 +633,7 @@ static inline bool fr_sbuff_terminal_search(fr_sbuff_t *in, char const *p, */ static inline int8_t terminal_cmp(fr_sbuff_term_elem_t const *a, fr_sbuff_term_elem_t const *b) { - MEMCMP_RETURN(a, b, str, len); - return 0; + return MEMCMP_FIELDS(a, b, str, len); } #if 0 diff --git a/src/modules/rlm_cache/drivers/rlm_cache_rbtree/rlm_cache_rbtree.c b/src/modules/rlm_cache/drivers/rlm_cache_rbtree/rlm_cache_rbtree.c index 8ab498b302a..caaef321abd 100644 --- a/src/modules/rlm_cache/drivers/rlm_cache_rbtree/rlm_cache_rbtree.c +++ b/src/modules/rlm_cache/drivers/rlm_cache_rbtree/rlm_cache_rbtree.c @@ -51,8 +51,7 @@ static int8_t cache_entry_cmp(void const *one, void const *two) { rlm_cache_entry_t const *a = one, *b = two; - MEMCMP_RETURN(a, b, key.vb_strvalue, key.vb_length); - return 0; + return MEMCMP_FIELDS(a, b, key.vb_strvalue, key.vb_length); } /** Compare two entries by expiry time