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

View File

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

View File

@ -9679,6 +9679,9 @@ void NumberFormatTest::Test20956_MonetarySymbolGetters() {
IcuTestErrorCode status(*this, "Test20956_MonetarySymbolGetters"); IcuTestErrorCode status(*this, "Test20956_MonetarySymbolGetters");
LocalPointer<DecimalFormat> decimalFormat(static_cast<DecimalFormat*>( LocalPointer<DecimalFormat> decimalFormat(static_cast<DecimalFormat*>(
NumberFormat::createCurrencyInstance("et", status))); NumberFormat::createCurrencyInstance("et", status)));
if (status.errDataIfFailureAndReset()) {
return;
}
decimalFormat->setCurrency(u"EEK"); decimalFormat->setCurrency(u"EEK");
@ -9823,6 +9826,9 @@ void NumberFormatTest::Test20961_CurrencyPluralPattern() {
{ {
LocalPointer<DecimalFormat> decimalFormat(static_cast<DecimalFormat*>( LocalPointer<DecimalFormat> decimalFormat(static_cast<DecimalFormat*>(
NumberFormat::createInstance("en-US", UNUM_CURRENCY_PLURAL, status))); NumberFormat::createInstance("en-US", UNUM_CURRENCY_PLURAL, status)));
if (status.errDataIfFailureAndReset()) {
return;
}
UnicodeString result; UnicodeString result;
decimalFormat->toPattern(result); decimalFormat->toPattern(result);
assertEquals("Currency pattern", u"#,##0.00 ¤¤¤", 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)); BASIC_TRANSLITERATOR_ID[i], UTRANS_FORWARD, parseError, status));
if (translit.get() == nullptr || !U_SUCCESS(status)) { if (translit.get() == nullptr || !U_SUCCESS(status)) {
dataerrln("FAIL: createInstance %s failed", BASIC_TRANSLITERATOR_ID[i]); dataerrln("FAIL: createInstance %s failed", BASIC_TRANSLITERATOR_ID[i]);
continue;
} }
UnicodeString data(TEST_DATA); UnicodeString data(TEST_DATA);
UnicodeString expected(EXPECTED_RESULTS[i]); UnicodeString expected(EXPECTED_RESULTS[i]);
@ -1570,6 +1571,7 @@ void TransliteratorTest::TestBasicTransliteratorEvenWithoutData() {
dataerrln(UnicodeString("FAIL: expected translit(") + dataerrln(UnicodeString("FAIL: expected translit(") +
BASIC_TRANSLITERATOR_ID[i] + ") = '" + BASIC_TRANSLITERATOR_ID[i] + ") = '" +
EXPECTED_RESULTS[i] + "' but got '" + data); EXPECTED_RESULTS[i] + "' but got '" + data);
continue;
} }
} }
for (int32_t i=0; BASIC_TRANSLITERATOR_RULES[i]; i++) { 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)); BASIC_TRANSLITERATOR_RULES[i], UTRANS_FORWARD, parseError, status));
if (translit.get() == nullptr || !U_SUCCESS(status)) { if (translit.get() == nullptr || !U_SUCCESS(status)) {
dataerrln("FAIL: createFromRules %s failed", BASIC_TRANSLITERATOR_RULES[i]); dataerrln("FAIL: createFromRules %s failed", BASIC_TRANSLITERATOR_RULES[i]);
continue;
} }
} }
} }