From a40716088ab08fa708b2b2ba5024c3c62eee8805 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Thu, 26 Nov 2020 15:29:01 -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 Change-Id: I8e05f270eae71cb15848075c4dfae80e8070fd80 --- libcounter/counter-api.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libcounter/counter-api.h b/libcounter/counter-api.h index 0a7c0ade..d18fa16e 100644 --- a/libcounter/counter-api.h +++ b/libcounter/counter-api.h @@ -104,7 +104,7 @@ static inline int __lttng_counter_add(const struct lib_counter_config *config, } if (v > 0 && (v >= UINT8_MAX || n < old)) overflow = true; - else if (v < 0 && (v <= -UINT8_MAX || n > old)) + else if (v < 0 && (v <= -(int64_t) UINT8_MAX || n > old)) underflow = true; break; } @@ -143,7 +143,7 @@ static inline int __lttng_counter_add(const struct lib_counter_config *config, } if (v > 0 && (v >= UINT16_MAX || n < old)) overflow = true; - else if (v < 0 && (v <= -UINT16_MAX || n > old)) + else if (v < 0 && (v <= -(int64_t) UINT16_MAX || n > old)) underflow = true; break; } @@ -182,7 +182,7 @@ static inline int __lttng_counter_add(const struct lib_counter_config *config, } if (v > 0 && (v >= UINT32_MAX || n < old)) overflow = true; - else if (v < 0 && (v <= -UINT32_MAX || n > old)) + else if (v < 0 && (v <= -(int64_t) UINT32_MAX || n > old)) underflow = true; break; } -- 2.34.1