@@ -183,6 +183,12 @@ static const char * const LOC_PREFERRED_GRANDFATHERED[] = {
183183 nullptr
184184};
185185
186+ struct char_deleter {
187+ void operator ()(void *p) const {
188+ efree (p);
189+ }
190+ };
191+
186192/* returns true if a is an ID separator, false otherwise */
187193#define isIDSeparator (a ) (a == ' _' || a == ' -' )
188194#define isKeywordSeparator (a ) (a == ' @' )
@@ -557,12 +563,6 @@ static void get_icu_disp_value_src_php( const char* tag_name, INTERNAL_FUNCTION_
557563 size_t disp_loc_name_len = 0 ;
558564 int free_loc_name = 0 ;
559565
560- struct char_deleter {
561- void operator ()(void *p) const {
562- efree (p);
563- }
564- };
565-
566566 std::unique_ptr<UChar, char_deleter> disp_name;
567567 int32_t disp_name_len = 0 ;
568568
@@ -619,7 +619,7 @@ static void get_icu_disp_value_src_php( const char* tag_name, INTERNAL_FUNCTION_
619619 /* Get the disp_value for the given locale */
620620 do {
621621 auto tmp = reinterpret_cast <UChar *>(erealloc ( disp_name.release () , buflen * sizeof (UChar) ));
622- disp_name = std::unique_ptr<UChar, char_deleter> (tmp);
622+ disp_name. reset (tmp);
623623 disp_name_len = buflen;
624624
625625 auto p_mod_loc_name = mod_loc_name.get ();
@@ -1171,7 +1171,7 @@ static zend_string* get_private_subtags(const char* loc_name)
11711171static int add_array_entry (const char * loc_name, zval* hash_arr, const char * key_name)
11721172{
11731173 zend_string* key_value = nullptr ;
1174- char * cur_key_name = nullptr ;
1174+ std::unique_ptr< char , char_deleter> cur_key_name ;
11751175 char * token = nullptr ;
11761176 char * last_ptr = nullptr ;
11771177
@@ -1191,18 +1191,16 @@ static int add_array_entry(const char* loc_name, zval* hash_arr, const char* key
11911191 int cnt = 0 ;
11921192 /* Tokenize on the "_" or "-" */
11931193 token = php_strtok_r ( key_value->val , DELIMITER ,&last_ptr);
1194- if ( cur_key_name ){
1195- efree ( cur_key_name);
1196- }
11971194 /* Over-allocates a few bytes for the integer so we don't have to reallocate. */
11981195 size_t cur_key_name_size = (sizeof (" -2147483648" ) - 1 ) + strlen (key_name) + 1 ;
1199- cur_key_name = reinterpret_cast <char *>(emalloc (cur_key_name_size));
1200- snprintf ( cur_key_name, cur_key_name_size , " %s%d" , key_name , cnt++);
1201- add_assoc_string ( hash_arr, cur_key_name , token);
1196+ cur_key_name.reset (reinterpret_cast <char *>(emalloc (cur_key_name_size)));
1197+ char *p_cur_key_name = cur_key_name.get ();
1198+ snprintf ( p_cur_key_name, cur_key_name_size , " %s%d" , key_name , cnt++);
1199+ add_assoc_string ( hash_arr, p_cur_key_name , token);
12021200 /* tokenize on the "_" or "-" and stop at singleton if any */
12031201 while ( (token = php_strtok_r (nullptr , DELIMITER , &last_ptr)) && (strlen (token)>1 ) ){
1204- snprintf ( cur_key_name , cur_key_name_size, " %s%d" , key_name , cnt++);
1205- add_assoc_string ( hash_arr, cur_key_name , token);
1202+ snprintf ( p_cur_key_name , cur_key_name_size, " %s%d" , key_name , cnt++);
1203+ add_assoc_string ( hash_arr, p_cur_key_name , token);
12061204 }
12071205/*
12081206 if( strcmp(key_name, LOC_PRIVATE_TAG) == 0 ){
@@ -1220,10 +1218,6 @@ static int add_array_entry(const char* loc_name, zval* hash_arr, const char* key
12201218 zend_string_release_ex (key_value, 0 );
12211219 }
12221220 }
1223-
1224- if ( cur_key_name ){
1225- efree ( cur_key_name);
1226- }
12271221 /* if( key_name != LOC_PRIVATE_TAG && key_value){*/
12281222 return cur_result;
12291223}
0 commit comments