diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2025-05-21 19:53:39 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2025-05-21 19:53:39 (GMT) |
commit | 0df6ab6d81a9f8de884aa8283d5c060ab1f7067e (patch) | |
tree | 0521a6f5ca3c6720349c358224ceabc5868d70d3 | |
parent | 8dbf9b344bb90dedbd42f93c67d28d76944dccbb (diff) |
Improve sized binary comparison.
-rw-r--r-- | src/common/sort.h | 3 | ||||
-rw-r--r-- | src/common/szbin.h | 16 |
2 files changed, 10 insertions, 9 deletions
diff --git a/src/common/sort.h b/src/common/sort.h index 39a6f33..27e3739 100644 --- a/src/common/sort.h +++ b/src/common/sort.h @@ -37,6 +37,9 @@ int sort_boolean(bool, bool); /* Compare une valeur avec une autre. */ int sort_unsigned_long(unsigned long, unsigned long); +#define sort_size(v1, v2) \ + sort_unsigned_long(v1, v2) + /* Compare une valeur avec une autre. */ int sort_signed_long_long(signed long long, signed long long); diff --git a/src/common/szbin.h b/src/common/szbin.h index 182739a..8524ae3 100644 --- a/src/common/szbin.h +++ b/src/common/szbin.h @@ -143,15 +143,13 @@ typedef struct _sized_binary_t while (0) -#define memcmp_sized_binary(s1, s2) \ - ({ \ - int __ret; \ - size_t __n; \ - __n = (s1)->size < (s2)->size ? (s1)->size : (s2)->size; \ - __ret = memcmp((s1)->data, (s2)->data, __n); \ - if (__ret == 0) \ - __ret = sort_unsigned_long_long((s1)->size, (s2)->size);\ - __ret; \ +#define memcmp_sized_binary(s1, s2) \ + ({ \ + int __ret; \ + __ret = sort_size((s1)->size, (s2)->size); \ + if (__ret == 0) \ + __ret = memcmp((s1)->data, (s2)->data, (s1)->size); \ + __ret; \ }) |