Make unsigned-integer-overflow sanitizer happy (#1377)

This commit is contained in:
Victor Zverovich 2019-10-28 14:30:56 -07:00
parent 40414b3446
commit 58c6f8c7f5

View File

@ -1410,7 +1410,8 @@ template <typename Range> class basic_writer {
template <typename Int> void write_decimal(Int value) { template <typename Int> void write_decimal(Int value) {
auto abs_value = static_cast<uint32_or_64_or_128_t<Int>>(value); auto abs_value = static_cast<uint32_or_64_or_128_t<Int>>(value);
bool is_negative = internal::is_negative(value); bool is_negative = internal::is_negative(value);
if (is_negative) abs_value = 0 - abs_value; // Don't do -abs_value since it trips unsigned-integer-overflow sanitizer.
if (is_negative) abs_value = ~abs_value + 1;
int num_digits = internal::count_digits(abs_value); int num_digits = internal::count_digits(abs_value);
auto&& it = auto&& it =
reserve((is_negative ? 1 : 0) + static_cast<size_t>(num_digits)); reserve((is_negative ? 1 : 0) + static_cast<size_t>(num_digits));