mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-02 06:20:09 +00:00
Make unsigned-integer-overflow sanitizer happy (#1377)
This commit is contained in:
parent
40414b3446
commit
58c6f8c7f5
@ -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));
|
||||||
|
Loading…
Reference in New Issue
Block a user