diff options
author | Rob Barnes <robbarnes@google.com> | 2023-03-01 07:15:13 -0700 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-03-02 00:46:44 +0000 |
commit | 07c07943a69a6788280cc04d317374f73a3735f3 (patch) | |
tree | 283f7a3596035b177d95b63a1384f66aff55549d | |
parent | c6e6f94b94243f1d462b4972d7ae64dbfd2e3635 (diff) | |
download | chrome-ec-07c07943a69a6788280cc04d317374f73a3735f3.tar.gz |
util: Switch MIN/MAX from inline to macro
The MIN/MAX in util/misc_util.h is an inline function with signed
int arguments. This fails when the arguments are unsigned or larger than
an int.
Switch the implementation to a MACRO. Borrowed the implementation from
include/util.h.
BUG=None
TEST=Run ectool
Change-Id: I06f478bec09dcafb3e20189dc43b21165ee109c9
Signed-off-by: Rob Barnes <robbarnes@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4299570
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r-- | util/misc_util.h | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/util/misc_util.h b/util/misc_util.h index d514a2516e..6c0a43fb23 100644 --- a/util/misc_util.h +++ b/util/misc_util.h @@ -6,15 +6,26 @@ #ifndef __UTIL_MISC_UTIL_H #define __UTIL_MISC_UTIL_H -/* Don't use a macro where an inline will do... */ -static inline int MIN(int a, int b) -{ - return a < b ? a : b; -} -static inline int MAX(int a, int b) -{ - return a > b ? a : b; -} +#define GENERIC_MAX(x, y) ((x) > (y) ? (x) : (y)) +#define GENERIC_MIN(x, y) ((x) < (y) ? (x) : (y)) +#ifndef MAX +#define MAX(a, b) \ + ({ \ + __typeof__(a) temp_a = (a); \ + __typeof__(b) temp_b = (b); \ + \ + GENERIC_MAX(temp_a, temp_b); \ + }) +#endif +#ifndef MIN +#define MIN(a, b) \ + ({ \ + __typeof__(a) temp_a = (a); \ + __typeof__(b) temp_b = (b); \ + \ + GENERIC_MIN(temp_a, temp_b); \ + }) +#endif /** * Write a buffer to the file. |