Skip to content

Commit b6c7d64

Browse files
committed
ICU-23109 Early return on error
1 parent 3ec40b8 commit b6c7d64

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

icu4c/source/i18n/nfrule.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,17 @@ NFRule::makeRules(UnicodeString& description,
113113
NFRuleList& rules,
114114
UErrorCode& status)
115115
{
116+
if (U_FAILURE(status)) {
117+
return;
118+
}
116119
// we know we're making at least one rule, so go ahead and
117120
// new it up and initialize its basevalue and divisor
118121
// (this also strips the rule descriptor, if any, off the
119122
// description string)
120123
LocalPointer<NFRule> rule1(new NFRule(rbnf, description, status));
124+
if (U_FAILURE(status)) {
125+
return;
126+
}
121127
/* test for nullptr */
122128
if (rule1.isNull()) {
123129
status = U_MEMORY_ALLOCATION_ERROR;
@@ -141,6 +147,9 @@ NFRule::makeRules(UnicodeString& description,
141147
|| rule1->getType() == kNaNRule)
142148
{
143149
rule1->extractSubstitutions(owner, description, predecessor, status);
150+
if (U_FAILURE(status)) {
151+
return;
152+
}
144153
}
145154
else {
146155
// if the description does contain a matched pair of brackets,
@@ -164,6 +173,9 @@ NFRule::makeRules(UnicodeString& description,
164173
// increment the original rule's base value ("rule1" actually
165174
// goes SECOND in the rule set's rule list)
166175
rule2.adoptInstead(new NFRule(rbnf, UnicodeString(), status));
176+
if (U_FAILURE(status)) {
177+
return;
178+
}
167179
/* test for nullptr */
168180
if (rule2.isNull()) {
169181
status = U_MEMORY_ALLOCATION_ERROR;
@@ -207,6 +219,9 @@ NFRule::makeRules(UnicodeString& description,
207219
sbuf.append(description, brack2 + 1, description.length() - brack2 - 1);
208220
}
209221
rule2->extractSubstitutions(owner, sbuf, predecessor, status);
222+
if (U_FAILURE(status)) {
223+
return;
224+
}
210225
}
211226

212227
// rule1's text includes the text in the brackets but omits
@@ -223,6 +238,9 @@ NFRule::makeRules(UnicodeString& description,
223238
sbuf.append(description, brack2 + 1, description.length() - brack2 - 1);
224239
}
225240
rule1->extractSubstitutions(owner, sbuf, predecessor, status);
241+
if (U_FAILURE(status)) {
242+
return;
243+
}
226244

227245
// if we only have one rule, return it; if we have two, return
228246
// a two-element array containing them (notice that rule2 goes

0 commit comments

Comments
 (0)