ICU-21174 Add a memory allocation check in MeasureUnit.

This commit is contained in:
Hugo van der Merwe 2020-08-06 02:05:40 +02:00
parent 8bd1f49ab6
commit abdf0e667d

View file

@ -861,6 +861,10 @@ LocalArray<MeasureUnit> MeasureUnit::splitToSingleUnits(int32_t& outCount, UErro
const MeasureUnitImpl& impl = MeasureUnitImpl::forMeasureUnit(*this, temp, status);
outCount = impl.units.length();
MeasureUnit* arr = new MeasureUnit[outCount];
if (arr == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
return LocalArray<MeasureUnit>();
}
for (int32_t i = 0; i < outCount; i++) {
arr[i] = impl.units[i]->build(status);
}