]> granicus.if.org Git - icu/commitdiff
ICU-11295 Fix getNumberFormatForField so that it returns either a valid pointer or...
authorTravis Keep <keep94@gmail.com>
Mon, 8 Dec 2014 19:35:38 +0000 (19:35 +0000)
committerTravis Keep <keep94@gmail.com>
Mon, 8 Dec 2014 19:35:38 +0000 (19:35 +0000)
X-SVN-Rev: 36822

icu4c/source/i18n/smpdtfmt.cpp
icu4c/source/test/intltest/sdtfmtts.cpp

index 4ba8d27a7609d8c299a77160d30addfb2c26202a..18a444dd84a3339a99b53a5adac8ecba802322f8 100644 (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);
 }
 
index ce043b21d58025dbd1f6bc38b8747aa17d02636d..546b43ccac9f4ad475346bb9f4230100f4fb5635 100644 (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 */