From 58c6f8c7f5e02ad396eb0e39fcf441bdb714ca1c Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Mon, 28 Oct 2019 14:30:56 -0700 Subject: [PATCH] Make unsigned-integer-overflow sanitizer happy (#1377) --- include/fmt/format.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 41f9cc01..78660ab5 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1410,7 +1410,8 @@ template class basic_writer { template void write_decimal(Int value) { auto abs_value = static_cast>(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(num_digits));