ICU-11295 Fix getNumberFormatForField so that it returns either a valid pointer or NULL.

X-SVN-Rev: 36822
This commit is contained in:
Travis Keep 2014-12-08 19:35:38 +00:00
parent ba2a065004
commit 00c6bb79bf
2 changed files with 10 additions and 1 deletions

View File

@ -1807,6 +1807,9 @@ void SimpleDateFormat::adoptNumberFormat(const UnicodeString& fields, NumberForm
const NumberFormat *
SimpleDateFormat::getNumberFormatForField(UChar field) const {
UDateFormatField index = DateFormatSymbols::getPatternCharIndex(field);
if (index == UDAT_FIELD_COUNT) {
return NULL;
}
return &getNumberFormatByIndex(index);
}

View File

@ -1,7 +1,7 @@
/********************************************************************
* COPYRIGHT:
* Copyright (c) 1997-2012, International Business Machines Corporation and
* Copyright (c) 1997-2014, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
@ -269,6 +269,12 @@ void IntlTestSimpleDateFormatAPI::testAPI(/*char *par*/)
if ((double)udDate == 0.0) {
errln("ERROR: Parsing failed using 'Y' and 'e'");
}
// ====== Test ticket 11295 getNumberFormatForField returns wild pointer
if (object.getNumberFormatForField('B') != NULL) {
errln("B is not a valid field, "
"getNumberFormatForField should return NULL");
}
}
#endif /* #if !UCONFIG_NO_FORMATTING */