diff --git a/icu4c/source/common/locid.cpp b/icu4c/source/common/locid.cpp index 36508acaf5ca..afc8b81ca26c 100644 --- a/icu4c/source/common/locid.cpp +++ b/icu4c/source/common/locid.cpp @@ -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; + } } }