From b3c4aa79622e50dfd0507dc195bc3ee5ccc8b377 Mon Sep 17 00:00:00 2001 From: Lucian Grijincu Date: Wed, 11 May 2016 10:45:33 -0700 Subject: [PATCH] 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 --- folly/Format-inl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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_); -- 2.34.1