ICU-6176 Fix some Coverity warnings in the unlikely event that a date/time format isn't simple in the future.

X-SVN-Rev: 23430
This commit is contained in:
George Rhoten 2008-02-14 02:43:33 +00:00
parent de481fcaa5
commit 5547bb21de

View File

@ -302,29 +302,40 @@ DateTimePatternGenerator::addICUPatterns(const Locale& locale, UErrorCode& statu
UnicodeString dfPattern;
UnicodeString conflictingString;
UDateTimePatternConflict conflictingStatus;
SimpleDateFormat* df;
DateFormat* df;
if (U_FAILURE(status)) {
return;
}
// Load with ICU patterns
for (int32_t i=DateFormat::kFull; i<=DateFormat::kShort; i++) {
if ((df = (SimpleDateFormat*)DateFormat::createDateInstance((DateFormat::EStyle)i, locale))!= NULL) {
conflictingStatus = addPattern(df->toPattern(dfPattern), FALSE, conflictingString, status);
delete df;
if (U_FAILURE(status)) {
return;
}
DateFormat::EStyle style = (DateFormat::EStyle)i;
df = DateFormat::createDateInstance(style, locale);
if (df != NULL && df->getDynamicClassID() == SimpleDateFormat::getStaticClassID()) {
SimpleDateFormat* sdf = (SimpleDateFormat*)df;
conflictingStatus = addPattern(sdf->toPattern(dfPattern), FALSE, conflictingString, status);
}
// TODO Maybe we should return an error when the date format isn't simple.
delete df;
if (U_FAILURE(status)) {
return;
}
if ((df = (SimpleDateFormat*)DateFormat::createTimeInstance((DateFormat::EStyle)i, locale)) != NULL) {
conflictingStatus = addPattern(df->toPattern(dfPattern), FALSE, conflictingString, status);
delete df;
if (U_FAILURE(status)) {
return;
}
df = DateFormat::createTimeInstance(style, locale);
if (df != NULL && df->getDynamicClassID() == SimpleDateFormat::getStaticClassID()) {
SimpleDateFormat* sdf = (SimpleDateFormat*)df;
conflictingStatus = addPattern(sdf->toPattern(dfPattern), FALSE, conflictingString, status);
// HACK for hh:ss
if ( i==DateFormat::kMedium ) {
hackPattern = dfPattern;
}
}
// TODO Maybe we should return an error when the date format isn't simple.
delete df;
if (U_FAILURE(status)) {
return;
}
}
}