From f801323dd7650782241e276d5a2971fc37312fa8 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Thu, 26 Nov 2020 15:29:28 -0500 Subject: [PATCH] Fix: counter: cast UINT*_MAX to 64-bit signed type before negative (long long)-UINT32_MAX leads to value 1 which is not what we expect. This is due to implicit type promotion from unsigned to signed 32-bit integer. Apply this to 8-bit and 16-bit types as well even though they are not affected by this issue to keep things regular. Signed-off-by: Mathieu Desnoyers --- include/counter/counter-api.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/counter/counter-api.h b/include/counter/counter-api.h index 827fb6f8..02d709a1 100644 --- a/include/counter/counter-api.h +++ b/include/counter/counter-api.h @@ -83,7 +83,7 @@ static inline int __lttng_counter_add(const struct lib_counter_config *config, } if (v > 0 && (v >= U8_MAX || n < old)) overflow = true; - else if (v < 0 && (v <= -U8_MAX || n > old)) + else if (v < 0 && (v <= -(s64) U8_MAX || n > old)) underflow = true; break; } @@ -122,7 +122,7 @@ static inline int __lttng_counter_add(const struct lib_counter_config *config, } if (v > 0 && (v >= U16_MAX || n < old)) overflow = true; - else if (v < 0 && (v <= -U16_MAX || n > old)) + else if (v < 0 && (v <= -(s64) U16_MAX || n > old)) underflow = true; break; } @@ -161,7 +161,7 @@ static inline int __lttng_counter_add(const struct lib_counter_config *config, } if (v > 0 && (v >= U32_MAX || n < old)) overflow = true; - else if (v < 0 && (v <= -U32_MAX || n > old)) + else if (v < 0 && (v <= -(s64) U32_MAX || n > old)) underflow = true; break; } -- 2.34.1