Skip to content

Commit

Permalink
ICU-21613 Fix undefined behaviour in ComplexUnitsConverter::applyRounder
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovdm committed Nov 30, 2021
1 parent 0b50a5f commit 54e4120
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions icu4c/source/i18n/units_complexconverter.cpp
Expand Up @@ -183,7 +183,7 @@ MaybeStackVector<Measure> ComplexUnitsConverter::convert(double quantity,
} else {
quantity = remainder;
}
}
}
}

applyRounder(intValues, quantity, rounder, status);
Expand All @@ -210,7 +210,6 @@ MaybeStackVector<Measure> ComplexUnitsConverter::convert(double quantity,
}
}


// Transfer values into result and return:
for(int32_t i = 0, n = unitsConverters_.length(); i < n; ++i) {
U_ASSERT(tmpResult[i] != nullptr);
Expand All @@ -224,6 +223,12 @@ MaybeStackVector<Measure> ComplexUnitsConverter::convert(double quantity,
void ComplexUnitsConverter::applyRounder(MaybeStackArray<int64_t, 5> &intValues, double &quantity,
icu::number::impl::RoundingImpl *rounder,
UErrorCode &status) const {
if (uprv_isInfinite(quantity) || uprv_isNaN(quantity)) {
// Inf and NaN can't be rounded, and calculating `carry` below is known
// to fail on Gentoo on HPPA and OpenSUSE on riscv64. Nothing to do.
return;
}

if (rounder == nullptr) {
// Nothing to do for the quantity.
return;
Expand Down

0 comments on commit 54e4120

Please sign in to comment.