Avoid undefined negation in CFGAS_Decimal.FromInt32.
Allows test to run under UBSAN without warnings being logged.
Thanks to the charming quirks of C++ signed arithmetic, negating
std::numeric_limits<int>::min() isn't allowed. Instead, in a two's
complement world, at least it is its own inverse ...
Change-Id: Ie03a7e9b2a54a87ad7d6b6e6107154bcd0c60b81
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/52391
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/xfa/fgas/crt/cfgas_decimal.cpp b/xfa/fgas/crt/cfgas_decimal.cpp
index ea6a45f..701cda8 100644
--- a/xfa/fgas/crt/cfgas_decimal.cpp
+++ b/xfa/fgas/crt/cfgas_decimal.cpp
@@ -7,6 +7,7 @@
#include "xfa/fgas/crt/cfgas_decimal.h"
#include <algorithm>
+#include <limits>
#include <utility>
#include "core/fxcrt/fx_extension.h"
@@ -253,6 +254,9 @@
CFGAS_Decimal::CFGAS_Decimal(int32_t val) {
if (val >= 0) {
*this = CFGAS_Decimal(static_cast<uint32_t>(val));
+ } else if (val == std::numeric_limits<int32_t>::min()) {
+ *this = CFGAS_Decimal(static_cast<uint32_t>(val));
+ SetNegate();
} else {
*this = CFGAS_Decimal(static_cast<uint32_t>(-val));
SetNegate();