Skip to content

Commit d836fca

Browse files
committed
feedback
1 parent e6e5a66 commit d836fca

2 files changed

Lines changed: 6 additions & 8 deletions

File tree

ext/intl/formatter/formatter_parse.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ extern "C" {
2727
}
2828

2929
#include <locale.h>
30+
#include <memory>
3031

3132
#define ICU_LOCALE_BUG 1
3233

@@ -159,10 +160,9 @@ U_CFUNC PHP_FUNCTION( numfmt_parse_currency )
159160
}
160161

161162
icu::ParsePosition pp(position);
162-
icu::CurrencyAmount *currAmt = FORMATTER_OBJECT(nfo)->parseCurrency(ustr, pp);
163+
std::unique_ptr<icu::CurrencyAmount> currAmt(FORMATTER_OBJECT(nfo)->parseCurrency(ustr, pp));
163164

164165
if (currAmt == nullptr || pp.getErrorIndex() >= 0) {
165-
delete currAmt;
166166
INTL_DATA_ERROR_CODE(nfo) = U_PARSE_ERROR;
167167
INTL_METHOD_CHECK_STATUS( nfo, "Number parsing failed" );
168168
}
@@ -175,7 +175,6 @@ U_CFUNC PHP_FUNCTION( numfmt_parse_currency )
175175

176176
/* Convert parsed currency to UTF-8 and pass it back to caller. */
177177
icu::UnicodeString ucurrency(currAmt->getISOCurrency());
178-
delete currAmt;
179178

180179
zend_string *u8str = intl_charFromString(ucurrency, &INTL_DATA_ERROR_CODE(nfo));
181180
INTL_METHOD_CHECK_STATUS( nfo, "Currency conversion to UTF-8 failed" );

ext/intl/listformatter/listformatter_class.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ extern "C" {
2626
#include "listformatter_class.h"
2727
#include "listformatter_arginfo.h"
2828

29+
#include <memory>
30+
2931
static zend_object_handlers listformatter_handlers;
3032

3133
static void listformatter_free_obj(zend_object *object)
@@ -134,7 +136,7 @@ PHP_METHOD(IntlListFormatter, format)
134136
RETURN_EMPTY_STRING();
135137
}
136138

137-
UnicodeString *items = new UnicodeString[count];
139+
std::unique_ptr<UnicodeString[]> items(new UnicodeString[count]);
138140
uint32_t i = 0;
139141
zval *val;
140142

@@ -144,14 +146,12 @@ PHP_METHOD(IntlListFormatter, format)
144146

145147
str_val = zval_try_get_tmp_string(val, &tmp_str);
146148
if (UNEXPECTED(!str_val)) {
147-
delete[] items;
148149
RETURN_THROWS();
149150
}
150151
intl_stringFromChar(items[i], ZSTR_VAL(str_val), ZSTR_LEN(str_val), &conv_status);
151152
zend_tmp_string_release(tmp_str);
152153

153154
if (U_FAILURE(conv_status)) {
154-
delete[] items;
155155
intl_error_set(nullptr, conv_status, "Failed to convert string to UTF-16");
156156
RETURN_FALSE;
157157
}
@@ -162,8 +162,7 @@ PHP_METHOD(IntlListFormatter, format)
162162
UErrorCode status = U_ZERO_ERROR;
163163
UnicodeString result;
164164

165-
LISTFORMATTER_OBJECT(obj)->format(items, count, result, status);
166-
delete[] items;
165+
LISTFORMATTER_OBJECT(obj)->format(items.get(), count, result, status);
167166

168167
if (U_FAILURE(status)) {
169168
intl_error_set(nullptr, status, "Failed to format list");

0 commit comments

Comments
 (0)