Skip to content

Commit

Permalink
ICU-20034 ICU4C Locale assignment operator should set the locale to b…
Browse files Browse the repository at this point in the history
…ogus if OOM occurs. (#14)

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.
  • Loading branch information
jefgen authored and sffc committed Sep 26, 2018
1 parent a058df6 commit 2913d87
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions icu4c/source/common/locid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
}

Expand Down

0 comments on commit 2913d87

Please sign in to comment.