From: Douglas Bagnall Date: Wed, 3 Apr 2024 04:53:39 +0000 (+1300) Subject: ldb: add NUMERIC_CMP macro to ldb.h X-Git-Tag: tdb-1.4.11~1180 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=de1b94f79ea8694ecdddab4b455d539caa7e77e2;p=thirdparty%2Fsamba.git ldb: add NUMERIC_CMP macro to ldb.h In other places we tend to include tsort.h, which also has TYPESAFE_QSORT. ldb.h already has TYPESAFE_QSORT, so it might as well have NUMERIC_CMP. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15625 Signed-off-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- diff --git a/lib/ldb/include/ldb.h b/lib/ldb/include/ldb.h index e98300d9e8d..b6625d9d96e 100644 --- a/lib/ldb/include/ldb.h +++ b/lib/ldb/include/ldb.h @@ -2335,6 +2335,22 @@ do { \ } while (0) #endif +#ifndef NUMERIC_CMP +/* + * NUMERIC_CMP is a safe replacement for `a - b` in comparison + * functions. It will work on integers, pointers, and floats. + * + * Rather than + * + * return a - b; + * + * use + * + * return NUMERIC_CMP(a, b); + */ +#define NUMERIC_CMP(a, b) (((a) > (b)) - ((a) < (b))) +#endif + /**