ICU-20034 ICU4C Locale assignment operator should set the locale to bogus 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.
This commit is contained in:
Jeff Genovy 2018-08-01 22:44:39 -07:00 committed by Shane Carr
parent fe9db30ca6
commit cbaf075ac1
No known key found for this signature in database
GPG key ID: FCED3B24AAB18B5C

View 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;
}
}
}