Skip to content

Commit

Permalink
Make unsigned-integer-overflow sanitizer happy (#1377)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Oct 28, 2019
1 parent 40414b3 commit 58c6f8c
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -1410,7 +1410,8 @@ template <typename Range> class basic_writer {
template <typename Int> void write_decimal(Int value) {
auto abs_value = static_cast<uint32_or_64_or_128_t<Int>>(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);
auto&& it =
reserve((is_negative ? 1 : 0) + static_cast<size_t>(num_digits));
Expand Down

0 comments on commit 58c6f8c

Please sign in to comment.