diff --git a/icu4c/source/i18n/fpositer.cpp b/icu4c/source/i18n/fpositer.cpp index a654248495..eb405f9c34 100644 --- a/icu4c/source/i18n/fpositer.cpp +++ b/icu4c/source/i18n/fpositer.cpp @@ -62,7 +62,10 @@ void FieldPositionIterator::setData(UVector32 *adopt, UErrorCode& status) { // Verify that adopt has valid data, and update status if it doesn't. if (U_SUCCESS(status)) { if (adopt) { - if ((adopt->size() % 3) != 0) { + if (adopt->size() == 0) { + delete adopt; + adopt = NULL; + } else if ((adopt->size() % 3) != 0) { status = U_ILLEGAL_ARGUMENT_ERROR; } else { for (int i = 1; i < adopt->size(); i += 3) { diff --git a/icu4c/source/i18n/unicode/ufieldpositer.h b/icu4c/source/i18n/unicode/ufieldpositer.h index 75c7a97475..8dfa3df5a4 100644 --- a/icu4c/source/i18n/unicode/ufieldpositer.h +++ b/icu4c/source/i18n/unicode/ufieldpositer.h @@ -86,8 +86,8 @@ U_NAMESPACE_END /** * Get information for the next field in the formatted string to which this - * UFieldPositionIterator currently applies, or return FALSE if there are - * no more fields. + * UFieldPositionIterator currently applies, or return a negative value if there + * are no more fields. * @param fpositer * A pointer to the UFieldPositionIterator object containing iteration * state for the format fields. diff --git a/icu4c/source/test/cintltst/cdattst.c b/icu4c/source/test/cintltst/cdattst.c index 1671566072..3faa32ce4e 100644 --- a/icu4c/source/test/cintltst/cdattst.c +++ b/icu4c/source/test/cintltst/cdattst.c @@ -1748,6 +1748,7 @@ static void TestParseErrorReturnValue(void) { static const char localeForFields[] = "en_US"; /* zoneGMT[]defined above */ static const UDate date2015Feb25 = 1424841000000.0; /* Wednesday, February 25, 2015 at 5:10:00 AM GMT */ +static const UChar patNoFields[] = { 0x0027, 0x0078, 0x0078, 0x0078, 0x0027, 0 }; /* "'xxx'" */ typedef struct { int32_t field; @@ -1837,6 +1838,19 @@ static void TestFormatForFields(void) { } } + udat_applyPattern(udfmt, FALSE, patNoFields, -1); + status = U_ZERO_ERROR; + ulen = udat_formatForFields(udfmt, date2015Feb25, ubuf, kUBufFieldsLen, fpositer, &status); + if ( U_FAILURE(status) ) { + log_err("udat_formatForFields with no-field pattern fails, status %s\n", u_errorName(status)); + } else { + field = ufieldpositer_next(fpositer, &beginPos, &endPos); + if (field >= 0) { + log_err("udat_formatForFields with no-field pattern as \"%s\"; expect field < 0, get field %d range %d-%d\n", + aescstrdup(ubuf, ulen), field, beginPos, endPos); + } + } + ucal_close(ucal); udat_close(udfmt); }