From ab11db36868d166a06d8505aab3522cd90b8f2cd Mon Sep 17 00:00:00 2001 From: Michael Ow Date: Fri, 11 Jan 2008 19:42:41 +0000 Subject: [PATCH] ICU-6132 Add various error checks for fString. X-SVN-Rev: 23206 --- icu4c/source/i18n/fmtable.cpp | 38 +++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/icu4c/source/i18n/fmtable.cpp b/icu4c/source/i18n/fmtable.cpp index b767b332166..765810d4d8a 100644 --- a/icu4c/source/i18n/fmtable.cpp +++ b/icu4c/source/i18n/fmtable.cpp @@ -1,6 +1,6 @@ /* ******************************************************************************* -* Copyright (C) 1997-2006, International Business Machines Corporation and * +* Copyright (C) 1997-2008, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* * @@ -70,7 +70,9 @@ static inline UBool instanceOfMeasure(const UObject* a) { */ static inline Formattable* createArrayCopy(const Formattable* array, int32_t count) { Formattable *result = new Formattable[count]; - for (int32_t i=0; i @@ -398,6 +408,10 @@ Formattable::getInt64(UErrorCode& status) const return (int64_t)fValue.fDouble; } case Formattable::kObject: + if (fValue.fObject == NULL) { + status = U_MEMORY_ALLOCATION_ERROR; + return 0; + } // TODO Later replace this with instanceof call if (instanceOfMeasure(fValue.fObject)) { return ((const Measure*) fValue.fObject)-> @@ -424,6 +438,10 @@ Formattable::getDouble(UErrorCode& status) const case Formattable::kDouble: return fValue.fDouble; case Formattable::kObject: + if (fValue.fObject == NULL) { + status = U_MEMORY_ALLOCATION_ERROR; + return 0; + } // TODO Later replace this with instanceof call if (instanceOfMeasure(fValue.fObject)) { return ((const Measure*) fValue.fObject)-> @@ -545,7 +563,11 @@ Formattable::getString(UnicodeString& result, UErrorCode& status) const setError(status, U_INVALID_FORMAT_ERROR); result.setToBogus(); } else { - result = *fValue.fString; + if (fValue.fString == NULL) { + setError(status, U_MEMORY_ALLOCATION_ERROR); + } else { + result = *fValue.fString; + } } return result; } @@ -558,6 +580,10 @@ Formattable::getString(UErrorCode& status) const setError(status, U_INVALID_FORMAT_ERROR); return *getBogus(); } + if (fValue.fString == NULL) { + setError(status, U_MEMORY_ALLOCATION_ERROR); + return *getBogus(); + } return *fValue.fString; } @@ -569,6 +595,10 @@ Formattable::getString(UErrorCode& status) setError(status, U_INVALID_FORMAT_ERROR); return *getBogus(); } + if (fValue.fString == NULL) { + setError(status, U_MEMORY_ALLOCATION_ERROR); + return *getBogus(); + } return *fValue.fString; }