diff --git a/ext/intl/calendar/calendar_methods.cpp b/ext/intl/calendar/calendar_methods.cpp index 8e85b695db9b..e01f10aaba91 100644 --- a/ext/intl/calendar/calendar_methods.cpp +++ b/ext/intl/calendar/calendar_methods.cpp @@ -203,7 +203,7 @@ U_CFUNC PHP_FUNCTION(intlcal_get_available_locales) int32_t count; const Locale *availLocales = Calendar::getAvailableLocales(count); - array_init(return_value); + array_init_size(return_value, count); for (int i = 0; i < count; i++) { Locale locale = availLocales[i]; add_next_index_string(return_value, locale.getName()); diff --git a/ext/intl/dateformat/dateformat_parse.cpp b/ext/intl/dateformat/dateformat_parse.cpp index 667bbf98ac62..13cf56ad7d82 100644 --- a/ext/intl/dateformat/dateformat_parse.cpp +++ b/ext/intl/dateformat/dateformat_parse.cpp @@ -108,7 +108,7 @@ static void internal_parse_to_localtime(IntlDateFormatter_object *dfo, char* tex INTL_METHOD_CHECK_STATUS( dfo, "Date parsing failed" ); - array_init( return_value ); + array_init_size( return_value, 9 ); /* Add entries from various fields of the obtained parsed_calendar */ add_to_localtime_arr( dfo, return_value, parsed_calendar, UCAL_SECOND, CALENDAR_SEC); add_to_localtime_arr( dfo, return_value, parsed_calendar, UCAL_MINUTE, CALENDAR_MIN); diff --git a/ext/intl/locale/locale_methods.cpp b/ext/intl/locale/locale_methods.cpp index e325e14e0d49..1ee32a2f094e 100644 --- a/ext/intl/locale/locale_methods.cpp +++ b/ext/intl/locale/locale_methods.cpp @@ -457,7 +457,7 @@ static zend_string* get_icu_value_internal( const char* loc_name , const char* t efree( mod_loc_name); } - tag_value->len = strlen(tag_value->val); + tag_value->len = buflen; return tag_value; } /* }}} */ @@ -736,7 +736,7 @@ U_CFUNC PHP_FUNCTION( locale_get_keywords ) Z_PARAM_PATH(loc_name, loc_name_len) ZEND_PARSE_PARAMETERS_END(); - INTL_CHECK_LOCALE_LEN(strlen(loc_name)); + INTL_CHECK_LOCALE_LEN(loc_name_len); if(loc_name_len == 0) { loc_name = (char *)intl_locale_get_default(); @@ -1127,7 +1127,7 @@ U_CFUNC PHP_FUNCTION(locale_parse) Z_PARAM_PATH(loc_name, loc_name_len) ZEND_PARSE_PARAMETERS_END(); - INTL_CHECK_LOCALE_LEN(strlen(loc_name)); + INTL_CHECK_LOCALE_LEN(loc_name_len); if(loc_name_len == 0) { loc_name = (char *)intl_locale_get_default(); @@ -1318,7 +1318,7 @@ U_CFUNC PHP_FUNCTION(locale_filter_matches) if( token && (token==cur_lang_tag) ){ /* check if the char. after match is SEPARATOR */ - chrcheck = token + (strlen(cur_loc_range)); + chrcheck = token + can_loc_range->len; if( isIDSeparator(*chrcheck) || isKeywordSeparator(*chrcheck) || isEndOfTag(*chrcheck) ){ efree( cur_lang_tag ); efree( cur_loc_range ); @@ -1350,14 +1350,14 @@ U_CFUNC PHP_FUNCTION(locale_filter_matches) } /* end of if isCanonical */ else{ /* Convert to lower case for case-insensitive comparison */ - cur_lang_tag = reinterpret_cast(ecalloc( 1, strlen(lang_tag ) + 1)); + cur_lang_tag = reinterpret_cast(ecalloc(1, lang_tag_len + 1)); result = strToMatch( lang_tag , cur_lang_tag); if( result == 0) { efree( cur_lang_tag ); RETURN_FALSE; } - cur_loc_range = reinterpret_cast(ecalloc( 1, strlen(loc_range ) + 1)); + cur_loc_range = reinterpret_cast(ecalloc(1, loc_range_len + 1)); result = strToMatch( loc_range , cur_loc_range ); if( result == 0) { efree( cur_lang_tag ); @@ -1370,7 +1370,7 @@ U_CFUNC PHP_FUNCTION(locale_filter_matches) if( token && (token==cur_lang_tag) ){ /* check if the char. after match is SEPARATOR */ - chrcheck = token + (strlen(cur_loc_range)); + chrcheck = token + loc_range_len; if( isIDSeparator(*chrcheck) || isEndOfTag(*chrcheck) ){ efree( cur_lang_tag ); efree( cur_loc_range ); diff --git a/ext/intl/resourcebundle/resourcebundle_class.cpp b/ext/intl/resourcebundle/resourcebundle_class.cpp index 43823137e605..0053c7c5285f 100644 --- a/ext/intl/resourcebundle/resourcebundle_class.cpp +++ b/ext/intl/resourcebundle/resourcebundle_class.cpp @@ -339,6 +339,7 @@ U_CFUNC PHP_FUNCTION( resourcebundle_locales ) size_t bundlename_len = 0; const char * entry; int entry_len; + int32_t count; UEnumeration *icuenum; UErrorCode icuerror = U_ZERO_ERROR; @@ -361,10 +362,18 @@ U_CFUNC PHP_FUNCTION( resourcebundle_locales ) icuenum = ures_openAvailableLocales( bundlename, &icuerror ); INTL_CHECK_STATUS(icuerror, "Cannot fetch locales list"); + count = uenum_count(icuenum, &icuerror); + if (U_FAILURE(icuerror)) { + uenum_close(icuenum); + INTL_CHECK_STATUS(icuerror, "Cannot count locales list"); + } uenum_reset( icuenum, &icuerror ); - INTL_CHECK_STATUS(icuerror, "Cannot iterate locales list"); + if (U_FAILURE(icuerror)) { + uenum_close(icuenum); + INTL_CHECK_STATUS(icuerror, "Cannot iterate locales list"); + } - array_init( return_value ); + array_init_size(return_value, count); while ((entry = uenum_next( icuenum, &entry_len, &icuerror ))) { add_next_index_stringl( return_value, (char *) entry, entry_len); } diff --git a/ext/intl/transliterator/transliterator_methods.cpp b/ext/intl/transliterator/transliterator_methods.cpp index 2dce4612e7a2..9045d364514d 100644 --- a/ext/intl/transliterator/transliterator_methods.cpp +++ b/ext/intl/transliterator/transliterator_methods.cpp @@ -225,6 +225,7 @@ U_CFUNC PHP_FUNCTION( transliterator_list_ids ) { UEnumeration *en; const UChar *elem; + int32_t count; int32_t elem_len; UErrorCode status = U_ZERO_ERROR; @@ -236,7 +237,18 @@ U_CFUNC PHP_FUNCTION( transliterator_list_ids ) INTL_CHECK_STATUS( status, "Failed to obtain registered transliterators" ); - array_init( return_value ); + count = uenum_count(en, &status); + if (U_FAILURE(status)) { + uenum_close(en); + INTL_CHECK_STATUS(status, "Failed to count registered transliterators"); + } + uenum_reset(en, &status); + if (U_FAILURE(status)) { + uenum_close(en); + INTL_CHECK_STATUS(status, "Failed to iterate registered transliterators"); + } + + array_init_size(return_value, count); while( (elem = uenum_unext( en, &elem_len, &status )) ) { zend_string *el = intl_convert_utf16_to_utf8(elem, elem_len, &status );