From 31120cdfc4593190565bb12b064c2f416417e6af Mon Sep 17 00:00:00 2001 From: George Rhoten Date: Tue, 3 Oct 2006 19:11:36 +0000 Subject: [PATCH] ICU-5426 Fix last check-in. Handle the case when malloc fails. X-SVN-Rev: 20478 --- icu4c/source/common/uniset.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/icu4c/source/common/uniset.cpp b/icu4c/source/common/uniset.cpp index 6e2b8a65c7e..e82b3996c34 100644 --- a/icu4c/source/common/uniset.cpp +++ b/icu4c/source/common/uniset.cpp @@ -1852,10 +1852,15 @@ void UnicodeSet::releasePattern() { */ void UnicodeSet::setPattern(const UnicodeString& newPat) { releasePattern(); - patLen = newPat.length(); - pat = (UChar *)uprv_malloc((patLen + 1) * sizeof(UChar)); - newPat.extractBetween(0, patLen, pat); - pat[patLen] = 0; + int32_t newPatLen = newPat.length(); + pat = (UChar *)uprv_malloc((newPatLen + 1) * sizeof(UChar)); + if (pat) { + patLen = newPatLen; + newPat.extractBetween(0, patLen, pat); + pat[patLen] = 0; + } + // else we don't care if malloc failed. This was just a nice cache. + // We can regenerate an equivalent pattern later when requested. } U_NAMESPACE_END