From cbaf075ac1b154a11607fb5ffda025015df2ee7e Mon Sep 17 00:00:00 2001 From: Jeff Genovy <29107334+jefgen@users.noreply.github.com> Date: Wed, 1 Aug 2018 22:44:39 -0700 Subject: [PATCH] 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. --- icu4c/source/common/locid.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/icu4c/source/common/locid.cpp b/icu4c/source/common/locid.cpp index 36508acaf5c..afc8b81ca26 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; + } } } -- 2.40.0