@@ -179,6 +179,12 @@ static const char * const LOC_PREFERRED_GRANDFATHERED[] = {
179179 nullptr
180180};
181181
182+ struct char_deleter {
183+ void operator ()(void *p) const {
184+ efree (p);
185+ }
186+ };
187+
182188/* returns true if a is an ID separator, false otherwise */
183189#define isIDSeparator (a ) (a == ' _' || a == ' -' )
184190#define isKeywordSeparator (a ) (a == ' @' )
@@ -553,12 +559,6 @@ static void get_icu_disp_value_src_php( char* tag_name, INTERNAL_FUNCTION_PARAME
553559 size_t disp_loc_name_len = 0 ;
554560 int free_loc_name = 0 ;
555561
556- struct char_deleter {
557- void operator ()(void *p) const {
558- efree (p);
559- }
560- };
561-
562562 std::unique_ptr<UChar, char_deleter> disp_name;
563563 int32_t disp_name_len = 0 ;
564564
@@ -615,7 +615,7 @@ static void get_icu_disp_value_src_php( char* tag_name, INTERNAL_FUNCTION_PARAME
615615 /* Get the disp_value for the given locale */
616616 do {
617617 auto tmp = reinterpret_cast <UChar *>(erealloc ( disp_name.release () , buflen * sizeof (UChar) ));
618- disp_name = std::unique_ptr<UChar, char_deleter> (tmp);
618+ disp_name. reset (tmp);
619619 disp_name_len = buflen;
620620
621621 auto p_mod_loc_name = mod_loc_name.get ();
@@ -1056,7 +1056,7 @@ static zend_string* get_private_subtags(const char* loc_name)
10561056static int add_array_entry (const char * loc_name, zval* hash_arr, char * key_name)
10571057{
10581058 zend_string* key_value = nullptr ;
1059- char * cur_key_name = nullptr ;
1059+ std::unique_ptr< char , char_deleter> cur_key_name ;
10601060 char * token = nullptr ;
10611061 char * last_ptr = nullptr ;
10621062
@@ -1076,18 +1076,16 @@ static int add_array_entry(const char* loc_name, zval* hash_arr, char* key_name)
10761076 int cnt = 0 ;
10771077 /* Tokenize on the "_" or "-" */
10781078 token = php_strtok_r ( key_value->val , DELIMITER ,&last_ptr);
1079- if ( cur_key_name ){
1080- efree ( cur_key_name);
1081- }
10821079 /* Over-allocates a few bytes for the integer so we don't have to reallocate. */
10831080 size_t cur_key_name_size = (sizeof (" -2147483648" ) - 1 ) + strlen (key_name) + 1 ;
1084- cur_key_name = reinterpret_cast <char *>(emalloc (cur_key_name_size));
1085- snprintf ( cur_key_name, cur_key_name_size , " %s%d" , key_name , cnt++);
1086- add_assoc_string ( hash_arr, cur_key_name , token);
1081+ cur_key_name.reset (reinterpret_cast <char *>(emalloc (cur_key_name_size)));
1082+ char *p_cur_key_name = cur_key_name.get ();
1083+ snprintf ( p_cur_key_name, cur_key_name_size , " %s%d" , key_name , cnt++);
1084+ add_assoc_string ( hash_arr, p_cur_key_name , token);
10871085 /* tokenize on the "_" or "-" and stop at singleton if any */
10881086 while ( (token = php_strtok_r (nullptr , DELIMITER , &last_ptr)) && (strlen (token)>1 ) ){
1089- snprintf ( cur_key_name , cur_key_name_size, " %s%d" , key_name , cnt++);
1090- add_assoc_string ( hash_arr, cur_key_name , token);
1087+ snprintf ( p_cur_key_name , cur_key_name_size, " %s%d" , key_name , cnt++);
1088+ add_assoc_string ( hash_arr, p_cur_key_name , token);
10911089 }
10921090/*
10931091 if( strcmp(key_name, LOC_PRIVATE_TAG) == 0 ){
@@ -1105,10 +1103,6 @@ static int add_array_entry(const char* loc_name, zval* hash_arr, char* key_name)
11051103 zend_string_release_ex (key_value, 0 );
11061104 }
11071105 }
1108-
1109- if ( cur_key_name ){
1110- efree ( cur_key_name);
1111- }
11121106 /* if( key_name != LOC_PRIVATE_TAG && key_value){*/
11131107 return cur_result;
11141108}
0 commit comments