From d9b9952d7c90d83380e0ffd8750819003b51fcd7 Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Mon, 5 Oct 2020 20:02:18 +0200 Subject: [PATCH] counters: Avoid signed integer overflow UBSAN complains in debug mode when the counter value overflows: counters.hh:184:16: runtime error: signed integer overflow: 1 + 9223372036854775807 cannot be represented in type 'long int' Aborting on shard 0. Overflow is supposed to be supported. Let's silence it by using casts. Fixes #7330. --- counters.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/counters.hh b/counters.hh index f13d483208..11ac1b77e5 100644 --- a/counters.hh +++ b/counters.hh @@ -181,7 +181,7 @@ public: int64_t logical_clock() const { return _logical_clock; } counter_shard& update(int64_t value_delta, int64_t clock_increment) noexcept { - _value += value_delta; + _value = uint64_t(_value) + uint64_t(value_delta); // signed int overflow is undefined hence the cast _logical_clock += clock_increment; return *this; }