diff options
Diffstat (limited to 'firmware/2lib/include')
-rw-r--r-- | firmware/2lib/include/2common.h | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/firmware/2lib/include/2common.h b/firmware/2lib/include/2common.h index 81f56df5..7cd8c041 100644 --- a/firmware/2lib/include/2common.h +++ b/firmware/2lib/include/2common.h @@ -18,12 +18,19 @@ struct vb2_public_key; /* - * Return the greater of A and B. This is used in macros which calculate the + * Return the min/max of A and B. This is used in macros which calculate the * required buffer size, so can't be turned into a static inline function. */ -#ifndef VB2_MAX -#define VB2_MAX(A, B) ((A) > (B) ? (A) : (B)) -#endif +#define VB2_MIN(a, b) ({ \ + typeof(a) __vb2_min_a = (a); \ + typeof(b) __vb2_min_b = (b); \ + __vb2_min_a < __vb2_min_b ? __vb2_min_a : __vb2_min_b; \ + }) +#define VB2_MAX(a, b) ({ \ + typeof(a) __vb2_max_a = (a); \ + typeof(b) __vb2_max_b = (b); \ + __vb2_max_a > __vb2_max_b ? __vb2_max_a : __vb2_max_b; \ + }) /* Return the number of elements in an array */ #ifndef ARRAY_SIZE |