ICU-6132 Check null pointer before dereferencing in unesctrn, unistr, and unum.

X-SVN-Rev: 23253
This commit is contained in:
Michael Ow 2008-01-16 22:58:59 +00:00
parent 5e72fa288d
commit 4667cbc378
3 changed files with 20 additions and 9 deletions

View file

@ -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);
}
}
/**

View file

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

View file

@ -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) {