mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-08 23:10:40 +00:00
ICU-12014 fix float-cast-overflow in rbnf.cpp
X-SVN-Rev: 38102
This commit is contained in:
parent
3d76dd93d2
commit
8b03bbc037
1 changed files with 6 additions and 3 deletions
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue