diff --git a/icu4c/source/common/unistr.cpp b/icu4c/source/common/unistr.cpp index 36b472b620d..52fddf32214 100644 --- a/icu4c/source/common/unistr.cpp +++ b/icu4c/source/common/unistr.cpp @@ -1,6 +1,6 @@ /* ****************************************************************************** -* Copyright (C) 1999-2007, International Business Machines Corporation and * +* Copyright (C) 1999-2008, International Business Machines Corporation and * * others. All Rights Reserved. * ****************************************************************************** * @@ -1138,9 +1138,12 @@ UnicodeString::copy(int32_t start, int32_t limit, int32_t dest) { return; // Nothing to do; avoid bogus malloc call } UChar* text = (UChar*) uprv_malloc( sizeof(UChar) * (limit - start) ); - extractBetween(start, limit, text, 0); - insert(dest, text, 0, limit - start); - uprv_free(text); + // Check to make sure text is not null. + if (text != NULL) { + extractBetween(start, limit, text, 0); + insert(dest, text, 0, limit - start); + uprv_free(text); + } } /** diff --git a/icu4c/source/i18n/unesctrn.cpp b/icu4c/source/i18n/unesctrn.cpp index 45ced8b1e9b..c3d848d06e9 100644 --- a/icu4c/source/i18n/unesctrn.cpp +++ b/icu4c/source/i18n/unesctrn.cpp @@ -1,6 +1,6 @@ /* ********************************************************************** - * Copyright (c) 2001-2004, International Business Machines + * Copyright (c) 2001-2008, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************** * Date Name Description @@ -82,7 +82,10 @@ static UChar* copySpec(const UChar* spec) { } ++len; UChar *result = (UChar *)uprv_malloc(len*sizeof(UChar)); - uprv_memcpy(result, spec, len*sizeof(result[0])); + // Check for memory allocation error. + if (result != NULL) { + uprv_memcpy(result, spec, len*sizeof(result[0])); + } return result; } diff --git a/icu4c/source/i18n/unum.cpp b/icu4c/source/i18n/unum.cpp index 1ba90922843..513bfb87cbd 100644 --- a/icu4c/source/i18n/unum.cpp +++ b/icu4c/source/i18n/unum.cpp @@ -1,6 +1,6 @@ /* ******************************************************************************* -* Copyright (C) 1996-2007, International Business Machines +* Copyright (C) 1996-2008, International Business Machines * Corporation and others. All Rights Reserved. ******************************************************************************* * Modification History: @@ -271,8 +271,13 @@ unum_formatDoubleCurrency(const UNumberFormat* fmt, if (pos != 0) { fp.setField(pos->field); } - - Formattable n(new CurrencyAmount(number, currency, *status)); + CurrencyAmount *tempCurrAmnt = new CurrencyAmount(number, currency, *status); + // Check for null pointer. + if (tempCurrAmnt == NULL) { + *status = U_MEMORY_ALLOCATION_ERROR; + return -1; + } + Formattable n(tempCurrAmnt); ((const NumberFormat*)fmt)->format(n, res, fp, *status); if (pos != 0) {