Skip to content

Commit

Permalink
Remove uses of new/delete
Browse files Browse the repository at this point in the history
  • Loading branch information
catamorphism committed Oct 17, 2024
1 parent 740ca4f commit e15e62b
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions icu4c/source/i18n/messageformat2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,10 @@ FunctionContext MessageFormatter::makeFunctionContext(const FunctionOptions& opt
} else {
UErrorCode localStatus = U_ZERO_ERROR;
int32_t len = localeStr.length();
LocalArray<char> temp(new char[len + 1]);
localeStr.extract(0, len, temp.getAlias(), len);
Locale l = Locale::forLanguageTag(StringPiece(temp.getAlias(), len), localStatus);
char* buf = static_cast<char*>(uprv_malloc(len + 1));
localeStr.extract(0, len, buf, len);
Locale l = Locale::forLanguageTag(StringPiece(buf, len), localStatus);
uprv_free(buf);
if (U_SUCCESS(localStatus)) {
localeToUse = l;
} else {
Expand Down Expand Up @@ -422,18 +423,18 @@ void MessageFormatter::matchSelectorKeys(const UVector& keys,
LocalArray<UnicodeString> adoptedKeys(keysArr);

// Create an array to hold the output
int32_t* prefsArr = new int32_t[keysLen];
int32_t* prefsArr = static_cast<int32_t*>(uprv_malloc(keysLen * sizeof(int32_t)));
if (prefsArr == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
}
LocalArray<int32_t> adoptedPrefs(prefsArr);

int32_t prefsLen = 0;

// Call the selector
// Already checked for fallback, so it's safe to call takeValue()
LocalPointer<FunctionValue> rvVal(rv.takeValue(status));
rvVal->selectKeys(adoptedKeys.getAlias(), keysLen, adoptedPrefs.getAlias(), prefsLen,
rvVal->selectKeys(adoptedKeys.getAlias(), keysLen, prefsArr, prefsLen,
status);

// Update errors
Expand Down Expand Up @@ -461,6 +462,8 @@ void MessageFormatter::matchSelectorKeys(const UVector& keys,
keysOut.adoptElement(k, status);
CHECK_ERROR(status);
}

uprv_free(prefsArr);
}

// See https://github.com/unicode-org/message-format-wg/blob/main/spec/formatting.md#resolve-preferences
Expand Down

0 comments on commit e15e62b

Please sign in to comment.