]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
define MEMCMP_FIELDS() and use it
authorAlan T. DeKok <aland@freeradius.org>
Mon, 16 Mar 2026 21:47:10 +0000 (17:47 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 16 Mar 2026 21:47:10 +0000 (17:47 -0400)
which is a little clearer (and less wrappers) than MEMCMP_RETURN

src/include/build.h
src/lib/server/map_proc.c
src/lib/util/sbuff.c
src/modules/rlm_cache/drivers/rlm_cache_rbtree/rlm_cache_rbtree.c

index eb47d0fddedc4afb8a09286e381e0ccc53a13b2e..265838d0814df3c8086c0e86f1f135648e5590af 100644 (file)
@@ -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.
index 2826ce6758e0acc34fe2195f1805473fca5df4c0..6ea897d3e30376a3d4d8ac9d5cb9df233434e9a6 100644 (file)
@@ -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
index 35ef37812c3a16b48159451fa68b0b2176b92558..90fcdaa599236b0fc1ab2f4610f45413fab6b285 100644 (file)
@@ -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
index 8ab498b302a9e38a5c710236a48fe3a78db5e7e6..caaef321abdae059478f6176ac4d9b36f1a8f06c 100644 (file)
@@ -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