mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-14 17:24:01 +00:00
ICU-6132 Add memory allocation error checking in createZoneStrings().
X-SVN-Rev: 23205
This commit is contained in:
parent
853d42f9a4
commit
d357fc8b07
1 changed files with 23 additions and 8 deletions
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1997-2007, International Business Machines Corporation and *
|
||||
* Copyright (C) 1997-2008, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
|
@ -276,15 +276,30 @@ void
|
|||
DateFormatSymbols::createZoneStrings(const UnicodeString *const * otherStrings)
|
||||
{
|
||||
int32_t row, col;
|
||||
UBool failed = FALSE;
|
||||
|
||||
fZoneStrings = (UnicodeString **)uprv_malloc(fZoneStringsRowCount * sizeof(UnicodeString *));
|
||||
for (row=0; row<fZoneStringsRowCount; ++row)
|
||||
{
|
||||
fZoneStrings[row] = newUnicodeStringArray(fZoneStringsColCount);
|
||||
for (col=0; col<fZoneStringsColCount; ++col) {
|
||||
// fastCopyFrom() - see assignArray comments
|
||||
fZoneStrings[row][col].fastCopyFrom(otherStrings[row][col]);
|
||||
}
|
||||
if (fZoneStrings != NULL) {
|
||||
for (row=0; row<fZoneStringsRowCount; ++row)
|
||||
{
|
||||
fZoneStrings[row] = newUnicodeStringArray(fZoneStringsColCount);
|
||||
if (fZoneStrings[row] == NULL) {
|
||||
failed = TRUE;
|
||||
break;
|
||||
}
|
||||
for (col=0; col<fZoneStringsColCount; ++col) {
|
||||
// fastCopyFrom() - see assignArray comments
|
||||
fZoneStrings[row][col].fastCopyFrom(otherStrings[row][col]);
|
||||
}
|
||||
}
|
||||
}
|
||||
// If memory allocation failed, roll back and delete fZoneStrings
|
||||
if (failed) {
|
||||
for (int i = row; i >= 0; i--) {
|
||||
delete[] fZoneStrings[i];
|
||||
}
|
||||
uprv_free(fZoneStrings);
|
||||
fZoneStrings = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue