Skip to contentSkip to conversation

Fix: max_t/min_t macros are missing cast on input

PATCH New Mathieu Desnoyers 1 participant 1 message Nov 10, 2018 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 2/2 Fix: max_t/min_t macros are missing cast on input

The semantic expected from max_t and min_t is to perform the max/min comparison in the type provided as first parameter.

Cast the input parameters to the proper type before comparing them, rather than after. There is no more need to cast the result of the expression now that both inputs are cast to the right type.

---
 src/common/macros.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/common/macros.h +2 -2
index c521aacd..461202ff 100644
@@ -72,7 +72,7 @@ void *zmalloc(size_t len)
 #endif
 
 #ifndef max_t
-#define max_t(type, a, b)	((type) max(a, b))
+#define max_t(type, a, b)	max((type) a, (type) b)
 #endif
 
 #ifndef min
@@ -80,7 +80,7 @@ void *zmalloc(size_t len)
 #endif
 
 #ifndef min_t
-#define min_t(type, a, b)	((type) min(a, b))
+#define min_t(type, a, b)	min((type) a, (type) b)
 #endif
 
 #ifndef LTTNG_PACKED
Signature · 1 line
2.11.0