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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user