From: Lucian Grijincu Date: Wed, 11 May 2016 17:45:33 +0000 (-0700) Subject: folly: ubsan: format: avoid UB in abs(-INT_MIN) X-Git-Tag: 2016.07.26~248 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=b3c4aa79622e50dfd0507dc195bc3ee5ccc8b377;p=folly.git 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 --- diff --git a/folly/Format-inl.h b/folly/Format-inl.h index 35c0298e..48125dc5 100644 --- a/folly/Format-inl.h +++ b/folly/Format-inl.h @@ -443,7 +443,7 @@ class FormatValue< char sign; if (std::is_signed::value) { if (folly::is_negative(val_)) { - uval = static_cast(-val_); + uval = -static_cast(val_); sign = '-'; } else { uval = static_cast(val_);