ICU-20254 Handling OOM in AffixTokenMatcherWarehouse.

This commit is contained in:
Shane Carr 2019-02-15 00:45:31 -08:00 committed by Shane F. Carr
parent 7a4d70c634
commit 06ec8f531e
2 changed files with 16 additions and 4 deletions

View File

@ -109,7 +109,12 @@ void AffixPatternMatcherBuilder::consumeToken(AffixPatternType type, UChar32 cp,
} else {
// Case 3: the token is a non-ignorable literal.
addMatcher(fWarehouse.nextCodePointMatcher(cp));
if (auto* ptr = fWarehouse.nextCodePointMatcher(cp, status)) {
addMatcher(*ptr);
} else {
// OOM; unwind the stack
return;
}
}
fLastTypeOrCp = type != TYPE_CODEPOINT ? type : cp;
}
@ -152,8 +157,15 @@ IgnorablesMatcher& AffixTokenMatcherWarehouse::ignorables() {
return fSetupData->ignorables;
}
NumberParseMatcher& AffixTokenMatcherWarehouse::nextCodePointMatcher(UChar32 cp) {
return *fCodePoints.create(cp);
NumberParseMatcher* AffixTokenMatcherWarehouse::nextCodePointMatcher(UChar32 cp, UErrorCode& status) {
if (U_FAILURE(status)) {
return nullptr;
}
auto* result = fCodePoints.create(cp);
if (result == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
}
return result;
}

View File

@ -99,7 +99,7 @@ class U_I18N_API AffixTokenMatcherWarehouse : public UMemory {
IgnorablesMatcher& ignorables();
NumberParseMatcher& nextCodePointMatcher(UChar32 cp);
NumberParseMatcher* nextCodePointMatcher(UChar32 cp, UErrorCode& status);
private:
// NOTE: The following field may be unsafe to access after construction is done!