]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/i18n/rbt_set.cpp
ICU-400.37.tar.gz
[apple/icu.git] / icuSources / i18n / rbt_set.cpp
index dbc45076baed3aba18b6e1e077b71da71d7a0c9e..1553c4f041953b17d60a4e6fde3826753f9cc08f 100644 (file)
@@ -1,6 +1,6 @@
 /*
  **********************************************************************
- *   Copyright (C) 1999-2005, International Business Machines
+ *   Copyright (C) 1999-2008, International Business Machines
  *   Corporation and others.  All Rights Reserved.
  **********************************************************************
  *   Date        Name        Description
@@ -162,11 +162,14 @@ U_NAMESPACE_BEGIN
  */
 TransliterationRuleSet::TransliterationRuleSet(UErrorCode& status) : UMemory() {
     ruleVector = new UVector(&_deleteRule, NULL, status);
-    rules = NULL;
-    maxContextLength = 0;
+    if (U_FAILURE(status)) {
+        return;
+    }
     if (ruleVector == NULL) {
         status = U_MEMORY_ALLOCATION_ERROR;
     }
+    rules = NULL;
+    maxContextLength = 0;
 }
 
 /**
@@ -185,11 +188,19 @@ TransliterationRuleSet::TransliterationRuleSet(const TransliterationRuleSet& oth
     if (other.ruleVector != 0 && ruleVector != 0 && U_SUCCESS(status)) {
         len = other.ruleVector->size();
         for (i=0; i<len && U_SUCCESS(status); ++i) {
-            ruleVector->addElement(new TransliterationRule(
-              *(TransliterationRule*)other.ruleVector->elementAt(i)), status);
+            TransliterationRule *tempTranslitRule = new TransliterationRule(*(TransliterationRule*)other.ruleVector->elementAt(i));
+            // Null pointer test
+            if (tempTranslitRule == NULL) {
+                status = U_MEMORY_ALLOCATION_ERROR;
+                break;
+            }
+            ruleVector->addElement(tempTranslitRule, status);
+            if (U_FAILURE(status)) {
+                break;
+            }
         }
     }
-    if (other.rules != 0) {
+    if (other.rules != 0 && U_SUCCESS(status)) {
         UParseError p;
         freeze(p, status);
     }
@@ -434,17 +445,18 @@ UnicodeString& TransliterationRuleSet::toRules(UnicodeString& ruleSource,
  * (getTarget=false) or emitted (getTarget=true) by this set.
  */
 UnicodeSet& TransliterationRuleSet::getSourceTargetSet(UnicodeSet& result,
-                               UBool getTarget) const {
+                               UBool getTarget) const
+{
     result.clear();
     int32_t count = ruleVector->size();
     for (int32_t i=0; i<count; ++i) {
-    TransliterationRule* r =
-        (TransliterationRule*) ruleVector->elementAt(i);
-    if (getTarget) {
-        r->addTargetSetTo(result);
-    } else {
-        r->addSourceSetTo(result);
-    }
+        TransliterationRule* r =
+            (TransliterationRule*) ruleVector->elementAt(i);
+        if (getTarget) {
+            r->addTargetSetTo(result);
+        } else {
+            r->addSourceSetTo(result);
+        }
     }
     return result;
 }