]> granicus.if.org Git - icu/commitdiff
ICU-20254 Handling OOM in AffixTokenMatcherWarehouse.
authorShane Carr <shane@unicode.org>
Fri, 15 Feb 2019 08:45:31 +0000 (00:45 -0800)
committerShane F. Carr <shane@unicode.org>
Tue, 19 Feb 2019 05:38:17 +0000 (21:38 -0800)
icu4c/source/i18n/numparse_affixes.cpp
icu4c/source/i18n/numparse_affixes.h

index cc7fc8a69722bdf454577858cfa103867cdc83cc..6e00d9f6be19abb6401559461e43c515574801e6 100644 (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;
 }
 
 
index 8b693624fa56f7309154d4ffb4181750d2a083f0..e02b17ba2d0852052d0d4fbe6fe9639cc5aab4e1 100644 (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!