ICU-21040 Fix segfaults in no data tests

This commit is contained in:
Elango Cheran 2020-04-10 11:22:56 -07:00 committed by Elango
parent 7a434a413f
commit 3fb3929f80
4 changed files with 30 additions and 0 deletions

View File

@ -203,6 +203,9 @@ NumberFormatterImpl::macrosToMicroGenerator(const MacroProps& macros, bool safe,
patternStyle = CLDR_PATTERN_STYLE_CURRENCY;
}
pattern = utils::getPatternForStyle(macros.locale, nsName, patternStyle, status);
if (U_FAILURE(status)) {
return nullptr;
}
}
auto patternInfo = new ParsedPatternInfo();
if (patternInfo == nullptr) {
@ -211,6 +214,9 @@ NumberFormatterImpl::macrosToMicroGenerator(const MacroProps& macros, bool safe,
}
fPatternInfo.adoptInstead(patternInfo);
PatternParser::parseToPatternInfo(UnicodeString(pattern), *patternInfo, status);
if (U_FAILURE(status)) {
return nullptr;
}
/////////////////////////////////////////////////////////////////////////////////////
/// START POPULATING THE DEFAULT MICROPROPS AND BUILDING THE MICROPROPS GENERATOR ///
@ -241,6 +247,9 @@ NumberFormatterImpl::macrosToMicroGenerator(const MacroProps& macros, bool safe,
roundingMode = precision.fRoundingMode;
}
fMicros.rounder = {precision, roundingMode, currency, status};
if (U_FAILURE(status)) {
return nullptr;
}
// Grouping strategy
if (!macros.grouper.isBogus()) {
@ -323,6 +332,9 @@ NumberFormatterImpl::macrosToMicroGenerator(const MacroProps& macros, bool safe,
if (safe) {
fImmutablePatternModifier.adoptInstead(patternModifier->createImmutable(status));
}
if (U_FAILURE(status)) {
return nullptr;
}
// Outer modifier (CLDR units and currency long names)
if (isCldrUnit) {
@ -349,6 +361,9 @@ NumberFormatterImpl::macrosToMicroGenerator(const MacroProps& macros, bool safe,
// No outer modifier required
fMicros.modOuter = &fMicros.helpers.emptyWeakModifier;
}
if (U_FAILURE(status)) {
return nullptr;
}
// Compact notation
if (macros.notation.fType == Notation::NTN_COMPACT) {
@ -371,6 +386,9 @@ NumberFormatterImpl::macrosToMicroGenerator(const MacroProps& macros, bool safe,
fCompactHandler.adoptInstead(newCompactHandler);
chain = fCompactHandler.getAlias();
}
if (U_FAILURE(status)) {
return nullptr;
}
// Always add the pattern modifier as the last element of the chain.
if (safe) {

View File

@ -1943,6 +1943,9 @@ void DateIntervalFormatTest::testTicket20707() {
int32_t j = 0;
for (const UnicodeString skeleton : {u"hh", u"HH", u"kk", u"KK", u"jj", u"JJs", u"CC"}) {
LocalPointer<DateIntervalFormat> dtifmt(DateIntervalFormat::createInstance(skeleton, locale, status));
if (status.errDataIfFailureAndReset()) {
continue;
}
FieldPosition fposition;
UnicodeString result;
LocalPointer<Calendar> calendar(Calendar::createInstance(TimeZone::createTimeZone(timeZone), status));

View File

@ -9679,6 +9679,9 @@ void NumberFormatTest::Test20956_MonetarySymbolGetters() {
IcuTestErrorCode status(*this, "Test20956_MonetarySymbolGetters");
LocalPointer<DecimalFormat> decimalFormat(static_cast<DecimalFormat*>(
NumberFormat::createCurrencyInstance("et", status)));
if (status.errDataIfFailureAndReset()) {
return;
}
decimalFormat->setCurrency(u"EEK");
@ -9823,6 +9826,9 @@ void NumberFormatTest::Test20961_CurrencyPluralPattern() {
{
LocalPointer<DecimalFormat> decimalFormat(static_cast<DecimalFormat*>(
NumberFormat::createInstance("en-US", UNUM_CURRENCY_PLURAL, status)));
if (status.errDataIfFailureAndReset()) {
return;
}
UnicodeString result;
decimalFormat->toPattern(result);
assertEquals("Currency pattern", u"#,##0.00 ¤¤¤", result);

View File

@ -1562,6 +1562,7 @@ void TransliteratorTest::TestBasicTransliteratorEvenWithoutData() {
BASIC_TRANSLITERATOR_ID[i], UTRANS_FORWARD, parseError, status));
if (translit.get() == nullptr || !U_SUCCESS(status)) {
dataerrln("FAIL: createInstance %s failed", BASIC_TRANSLITERATOR_ID[i]);
continue;
}
UnicodeString data(TEST_DATA);
UnicodeString expected(EXPECTED_RESULTS[i]);
@ -1570,6 +1571,7 @@ void TransliteratorTest::TestBasicTransliteratorEvenWithoutData() {
dataerrln(UnicodeString("FAIL: expected translit(") +
BASIC_TRANSLITERATOR_ID[i] + ") = '" +
EXPECTED_RESULTS[i] + "' but got '" + data);
continue;
}
}
for (int32_t i=0; BASIC_TRANSLITERATOR_RULES[i]; i++) {
@ -1580,6 +1582,7 @@ void TransliteratorTest::TestBasicTransliteratorEvenWithoutData() {
BASIC_TRANSLITERATOR_RULES[i], UTRANS_FORWARD, parseError, status));
if (translit.get() == nullptr || !U_SUCCESS(status)) {
dataerrln("FAIL: createFromRules %s failed", BASIC_TRANSLITERATOR_RULES[i]);
continue;
}
}
}