]> granicus.if.org Git - icu/commitdiff
ICU-20034 ICU4C Locale assignment operator should set the locale to bogus if OOM...
authorJeff Genovy <29107334+jefgen@users.noreply.github.com>
Thu, 2 Aug 2018 05:44:39 +0000 (22:44 -0700)
committerShane Carr <shane@unicode.org>
Thu, 27 Sep 2018 21:27:37 +0000 (14:27 -0700)
ICU-20034 ICU4C the Locale class's assignment operator should set the locale to "bogus" if an OOM error occurs when attempting to copy data over from the other locale.
Also need to check strdup, as that calls malloc and it can fail too.

icu4c/source/common/locid.cpp

index 36508acaf5ca70c2fadba2fe1b5f6f0078dc5f97..afc8b81ca26c5180f1adaaf039432a33bba77e63 100644 (file)
@@ -444,6 +444,8 @@ Locale &Locale::operator=(const Locale &other)
     if(other.fullName != other.fullNameBuffer) {
         fullName = (char *)uprv_malloc(sizeof(char)*(uprv_strlen(other.fullName)+1));
         if (fullName == NULL) {
+            // if memory allocation fails, set this object to bogus.
+            fIsBogus = TRUE;
             return *this;
         }
     }
@@ -456,6 +458,11 @@ Locale &Locale::operator=(const Locale &other)
     } else {
         if (other.baseName) {
             baseName = uprv_strdup(other.baseName);
+            if (baseName == nullptr) {
+                // if memory allocation fails, set this object to bogus.
+                fIsBogus = TRUE;
+                return *this;
+            }
         }
     }