Commit b3c4aa79 authored by Lucian Grijincu's avatar Lucian Grijincu Committed by Facebook Github Bot 6

folly: ubsan: format: avoid UB in abs(-INT_MIN)

Summary:
abs(-INT_MIN) is UB. Avoid it by first casting the number to
its unsigned equivalent and then negating that.

Reviewed By: yfeldblum

Differential Revision: D3280835

fbshipit-source-id: 40922d686173e6467e15d5a6dc2b62ad718349b5
parent d618bf95
...@@ -443,7 +443,7 @@ class FormatValue< ...@@ -443,7 +443,7 @@ class FormatValue<
char sign; char sign;
if (std::is_signed<T>::value) { if (std::is_signed<T>::value) {
if (folly::is_negative(val_)) { if (folly::is_negative(val_)) {
uval = static_cast<UT>(-val_); uval = -static_cast<UT>(val_);
sign = '-'; sign = '-';
} else { } else {
uval = static_cast<UT>(val_); uval = static_cast<UT>(val_);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment