ICU-12014 fix float-cast-overflow in rbnf.cpp

X-SVN-Rev: 38102
This commit is contained in:
Andy Heninger 2015-12-02 22:31:56 +00:00
parent 3d76dd93d2
commit 8b03bbc037

View file

@ -1260,9 +1260,12 @@ RuleBasedNumberFormat::parse(const UnicodeString& text,
}
result = high_result;
if (result.getType() == Formattable::kDouble) {
int32_t r = (int32_t)result.getDouble();
if ((double)r == result.getDouble()) {
result.setLong(r);
double d = result.getDouble();
if (!uprv_isNaN(d) && d == uprv_trunc(d) && INT32_MIN <= d && d <= INT32_MAX) {
// Note: casting a double to an int when the double is too large or small
// to fit the destination is undefined behavior. The explicit range checks,
// above, are required. Just casting and checking the result value is undefined.
result.setLong(static_cast<int32_t>(d));
}
}
}