diff options
author | Stanislav Malyshev <stas@php.net> | 2014-12-29 02:17:15 -0800 |
---|---|---|
committer | Stanislav Malyshev <stas@php.net> | 2014-12-29 14:06:12 -0800 |
commit | 82f3d3658315513bdb8136371c6b46ea6297eb22 (patch) | |
tree | 6bdee5087d8b5a0c75db0ece8e20189cacfc090a /ext | |
parent | ee7decb7ff7b8e81b595c01cfb6b5719bb8c520e (diff) | |
download | php-git-82f3d3658315513bdb8136371c6b46ea6297eb22.tar.gz |
cleanup intl types
Diffstat (limited to 'ext')
44 files changed, 292 insertions, 303 deletions
diff --git a/ext/intl/breakiterator/breakiterator_iterators.cpp b/ext/intl/breakiterator/breakiterator_iterators.cpp index 624a813e54..2ff698b87e 100644 --- a/ext/intl/breakiterator/breakiterator_iterators.cpp +++ b/ext/intl/breakiterator/breakiterator_iterators.cpp @@ -168,11 +168,11 @@ static void _breakiterator_parts_move_forward(zend_object_iterator *iter) * No need to do anything, the engine increments ->index */ const char *s = Z_STRVAL(bio->text); - int32_t slen = Z_STRLEN(bio->text); + size_t slen = Z_STRLEN(bio->text); zend_string *res; if (next == BreakIterator::DONE) { - next = slen; + next = (int32_t)slen; } assert(next <= slen && next >= cur); res = zend_string_alloc(next - cur, 0); diff --git a/ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp b/ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp index be38396466..e359bacf41 100644 --- a/ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp +++ b/ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp @@ -33,7 +33,7 @@ static void _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAMETERS) { zval *object = getThis(); char *rules; - size_t rules_len; + size_t rules_len; zend_bool compiled = 0; UErrorCode status = U_ZERO_ERROR; intl_error_reset(NULL); @@ -123,7 +123,7 @@ U_CFUNC PHP_FUNCTION(rbbi_get_rules) BREAKITER_METHOD_FETCH_OBJECT; char *str; - int str_len; + size_t str_len; const UnicodeString rules = fetch_rbbi(bio)->getRules(); if (intl_charFromString(rules, &str, &str_len, BREAKITER_ERROR_CODE_P(bio)) == FAILURE) diff --git a/ext/intl/collator/collator_convert.c b/ext/intl/collator/collator_convert.c index 8ff63a902e..23fd00001d 100644 --- a/ext/intl/collator/collator_convert.c +++ b/ext/intl/collator/collator_convert.c @@ -45,10 +45,10 @@ static void collator_convert_hash_item_from_utf8_to_utf16( UErrorCode* status ) { const char* old_val; - int old_val_len; + size_t old_val_len; UChar* new_val = NULL; - int new_val_len = 0; - zval znew_val; + int32_t new_val_len = 0; + zval znew_val; /* Process string values only. */ if( Z_TYPE_P( hashData ) != IS_STRING ) @@ -86,10 +86,10 @@ static void collator_convert_hash_item_from_utf16_to_utf8( UErrorCode* status ) { const char* old_val; - int old_val_len; - char* new_val = NULL; - int new_val_len = 0; - zval znew_val; + size_t old_val_len; + char* new_val = NULL; + size_t new_val_len = 0; + zval znew_val; /* Process string values only. */ if( Z_TYPE_P( hashData ) != IS_STRING ) @@ -105,7 +105,7 @@ static void collator_convert_hash_item_from_utf16_to_utf8( return; /* Update current hash item with the converted value. */ - ZVAL_STRINGL( &znew_val, (char*)new_val, new_val_len); + ZVAL_STRINGL( &znew_val, new_val, new_val_len); //??? efree(new_val); @@ -171,7 +171,7 @@ zval* collator_convert_zstr_utf16_to_utf8( zval* utf16_zval, zval *rv ) { zval* utf8_zval = NULL; char* str = NULL; - int str_len = 0; + size_t str_len = 0; UErrorCode status = U_ZERO_ERROR; /* Convert to utf8 then. */ @@ -201,7 +201,7 @@ zval* collator_convert_zstr_utf8_to_utf16( zval* utf8_zval, zval *rv ) { zval* zstr = NULL; UChar* ustr = NULL; - int ustr_len = 0; + int32_t ustr_len = 0; UErrorCode status = U_ZERO_ERROR; /* Convert the string to UTF-16. */ @@ -230,7 +230,7 @@ zval* collator_convert_object_to_string( zval* obj, zval *rv ) zval* zstr = NULL; UErrorCode status = U_ZERO_ERROR; UChar* ustr = NULL; - int ustr_len = 0; + int32_t ustr_len = 0; /* Bail out if it's not an object. */ if( Z_TYPE_P( obj ) != IS_OBJECT ) diff --git a/ext/intl/collator/collator_create.c b/ext/intl/collator/collator_create.c index 3945fb78b3..2d98ea9d01 100644 --- a/ext/intl/collator/collator_create.c +++ b/ext/intl/collator/collator_create.c @@ -28,7 +28,7 @@ static void collator_ctor(INTERNAL_FUNCTION_PARAMETERS) { const char* locale; - size_t locale_len = 0; + size_t locale_len = 0; zval* object; Collator_object* co; diff --git a/ext/intl/collator/collator_is_numeric.c b/ext/intl/collator/collator_is_numeric.c index a93cd962f3..6b0568dd64 100644 --- a/ext/intl/collator/collator_is_numeric.c +++ b/ext/intl/collator/collator_is_numeric.c @@ -222,7 +222,7 @@ static zend_long collator_u_strtol(nptr, endptr, base) /* {{{ collator_is_numeric] * Taken from PHP6:is_numeric_unicode() */ -zend_uchar collator_is_numeric( UChar *str, int length, zend_long *lval, double *dval, int allow_errors ) +zend_uchar collator_is_numeric( UChar *str, int32_t length, zend_long *lval, double *dval, int allow_errors ) { zend_long local_lval; double local_dval; diff --git a/ext/intl/collator/collator_is_numeric.h b/ext/intl/collator/collator_is_numeric.h index 5ede4fa922..f6337aaacc 100644 --- a/ext/intl/collator/collator_is_numeric.h +++ b/ext/intl/collator/collator_is_numeric.h @@ -21,6 +21,6 @@ #include <php.h> #include <unicode/uchar.h> -zend_uchar collator_is_numeric( UChar *str, int length, zend_long *lval, double *dval, int allow_errors ); +zend_uchar collator_is_numeric( UChar *str, int32_t length, zend_long *lval, double *dval, int allow_errors ); #endif // COLLATOR_IS_NUMERIC_H diff --git a/ext/intl/collator/collator_sort.c b/ext/intl/collator/collator_sort.c index d0d6b1a9d9..8914736dee 100644 --- a/ext/intl/collator/collator_sort.c +++ b/ext/intl/collator/collator_sort.c @@ -536,9 +536,9 @@ PHP_FUNCTION( collator_asort ) PHP_FUNCTION( collator_get_sort_key ) { char* str = NULL; - size_t str_len = 0; + size_t str_len = 0; UChar* ustr = NULL; - int ustr_len = 0; + int32_t ustr_len = 0; uint8_t* key = NULL; int key_len = 0; diff --git a/ext/intl/common/common_date.cpp b/ext/intl/common/common_date.cpp index 326e8c01c9..f1bf75ab0f 100644 --- a/ext/intl/common/common_date.cpp +++ b/ext/intl/common/common_date.cpp @@ -43,7 +43,7 @@ U_CFUNC TimeZone *timezone_convert_datetimezone(int type, { char *id = NULL, offset_id[] = "GMT+00:00"; - int id_len = 0; + int32_t id_len = 0; char *message; TimeZone *timeZone; diff --git a/ext/intl/converter/converter.c b/ext/intl/converter/converter.c index f52d0490cc..c9ad9a9409 100644 --- a/ext/intl/converter/converter.c +++ b/ext/intl/converter/converter.c @@ -270,7 +270,7 @@ static void php_converter_append_fromUnicode_target(zval *val, UConverterFromUni return; case IS_STRING: { - int vallen = Z_STRLEN_P(val); + size_t vallen = Z_STRLEN_P(val); if (TARGET_CHECK(args, vallen)) { memcpy(args->target, Z_STRVAL_P(val), vallen); args->target += vallen; @@ -372,7 +372,7 @@ static inline zend_bool php_converter_set_callbacks(php_converter_object *objval /* {{{ php_converter_set_encoding */ static zend_bool php_converter_set_encoding(php_converter_object *objval, UConverter **pcnv, - const char *enc, int enc_len + const char *enc, size_t enc_len ) { UErrorCode error = U_ZERO_ERROR; UConverter *cnv = ucnv_open(enc, &error); diff --git a/ext/intl/dateformat/dateformat_attr.c b/ext/intl/dateformat/dateformat_attr.c index ee8b91dbed..60ef45b7b3 100644 --- a/ext/intl/dateformat/dateformat_attr.c +++ b/ext/intl/dateformat/dateformat_attr.c @@ -128,8 +128,8 @@ PHP_FUNCTION( datefmt_get_pattern ) PHP_FUNCTION( datefmt_set_pattern ) { char* value = NULL; - size_t value_len = 0; - int slength = 0; + size_t value_len = 0; + int32_t slength = 0; UChar* svalue = NULL; zend_bool is_pattern_localized =FALSE; diff --git a/ext/intl/dateformat/dateformat_attrcpp.cpp b/ext/intl/dateformat/dateformat_attrcpp.cpp index 52df471a10..1b9716eceb 100644 --- a/ext/intl/dateformat/dateformat_attrcpp.cpp +++ b/ext/intl/dateformat/dateformat_attrcpp.cpp @@ -45,7 +45,7 @@ static inline DateFormat *fetch_datefmt(IntlDateFormatter_object *dfo) { U_CFUNC PHP_FUNCTION(datefmt_get_timezone_id) { char *str; - int str_len; + size_t str_len; DATE_FORMAT_METHOD_INIT_VARS; if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", diff --git a/ext/intl/dateformat/dateformat_create.cpp b/ext/intl/dateformat/dateformat_create.cpp index 9a90029ca1..2ceee460ce 100644 --- a/ext/intl/dateformat/dateformat_create.cpp +++ b/ext/intl/dateformat/dateformat_create.cpp @@ -41,21 +41,21 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS) zval *object; const char *locale_str; - size_t locale_len = 0; + size_t locale_len = 0; Locale locale; - zend_long date_type = 0; - zend_long time_type = 0; + zend_long date_type = 0; + zend_long time_type = 0; zval *calendar_zv = NULL; Calendar *calendar = NULL; - zend_long calendar_type; + zend_long calendar_type; bool calendar_owned; zval *timezone_zv = NULL; TimeZone *timezone = NULL; bool explicit_tz; char* pattern_str = NULL; - size_t pattern_str_len = 0; + size_t pattern_str_len = 0; UChar* svalue = NULL; /* UTF-16 pattern_str */ - int slength = 0; + int32_t slength = 0; IntlDateFormatter_object* dfo; intl_error_reset(NULL); diff --git a/ext/intl/dateformat/dateformat_data.h b/ext/intl/dateformat/dateformat_data.h index aaf61e6266..ed61c75594 100644 --- a/ext/intl/dateformat/dateformat_data.h +++ b/ext/intl/dateformat/dateformat_data.h @@ -23,7 +23,7 @@ #include "intl_error.h" typedef struct { - // error hangling + // error handling intl_error error; // formatter handling diff --git a/ext/intl/dateformat/dateformat_format_object.cpp b/ext/intl/dateformat/dateformat_format_object.cpp index fe38a71287..1df6cc9612 100644 --- a/ext/intl/dateformat/dateformat_format_object.cpp +++ b/ext/intl/dateformat/dateformat_format_object.cpp @@ -63,7 +63,7 @@ U_CFUNC PHP_FUNCTION(datefmt_format_object) zval *object, *format = NULL; const char *locale_str = NULL; - size_t locale_len; + size_t locale_len; bool pattern = false; UDate date; TimeZone *timeZone = NULL; @@ -209,7 +209,7 @@ U_CFUNC PHP_FUNCTION(datefmt_format_object) { char *ret_str; - int ret_str_len; + size_t ret_str_len; UnicodeString result = UnicodeString(); df->format(date, result); diff --git a/ext/intl/dateformat/dateformat_parse.c b/ext/intl/dateformat/dateformat_parse.c index 7d12f877e7..15d19485ed 100644 --- a/ext/intl/dateformat/dateformat_parse.c +++ b/ext/intl/dateformat/dateformat_parse.c @@ -34,7 +34,7 @@ * if set to 1 - store any error encountered in the parameter parse_error * if set to 0 - no need to store any error encountered in the parameter parse_error */ -static void internal_parse_to_timestamp(IntlDateFormatter_object *dfo, char* text_to_parse, int32_t text_len, int32_t *parse_pos, zval *return_value) +static void internal_parse_to_timestamp(IntlDateFormatter_object *dfo, char* text_to_parse, size_t text_len, int32_t *parse_pos, zval *return_value) { double result = 0; UDate timestamp =0; @@ -81,7 +81,7 @@ static void add_to_localtime_arr( IntlDateFormatter_object *dfo, zval* return_va /* {{{ * Internal function which calls the udat_parseCalendar */ -static void internal_parse_to_localtime(IntlDateFormatter_object *dfo, char* text_to_parse, int32_t text_len, int32_t *parse_pos, zval *return_value) +static void internal_parse_to_localtime(IntlDateFormatter_object *dfo, char* text_to_parse, size_t text_len, int32_t *parse_pos, zval *return_value) { UCalendar *parsed_calendar = NULL; UChar* text_utf16 = NULL; diff --git a/ext/intl/formatter/formatter_attr.c b/ext/intl/formatter/formatter_attr.c index d3189df6d6..f5a4cafe3c 100644 --- a/ext/intl/formatter/formatter_attr.c +++ b/ext/intl/formatter/formatter_attr.c @@ -102,10 +102,10 @@ PHP_FUNCTION( numfmt_get_attribute ) PHP_FUNCTION( numfmt_get_text_attribute ) { zend_long attribute; - UChar value_buf[64]; - int value_buf_size = USIZE( value_buf ); - UChar* value = value_buf; - int length = 0; + UChar value_buf[64]; + int32_t value_buf_size = USIZE( value_buf ); + UChar* value = value_buf; + int32_t length = 0; FORMATTER_METHOD_INIT_VARS; /* Parse parameters. */ @@ -207,7 +207,7 @@ PHP_FUNCTION( numfmt_set_attribute ) */ PHP_FUNCTION( numfmt_set_text_attribute ) { - int slength = 0; + int32_t slength = 0; UChar *svalue = NULL; zend_long attribute; char *value; @@ -252,7 +252,7 @@ PHP_FUNCTION( numfmt_get_symbol ) zend_long symbol; UChar value_buf[4]; UChar *value = value_buf; - int length = USIZE(value_buf); + int32_t length = USIZE(value_buf); FORMATTER_METHOD_INIT_VARS; /* Parse parameters. */ @@ -297,11 +297,11 @@ PHP_FUNCTION( numfmt_get_symbol ) */ PHP_FUNCTION( numfmt_set_symbol ) { - zend_long symbol; + zend_long symbol; char* value = NULL; - size_t value_len = 0; + size_t value_len = 0; UChar* svalue = 0; - int slength = 0; + int32_t slength = 0; FORMATTER_METHOD_INIT_VARS; /* Parse parameters. */ @@ -344,9 +344,9 @@ PHP_FUNCTION( numfmt_set_symbol ) */ PHP_FUNCTION( numfmt_get_pattern ) { - UChar value_buf[64]; - int length = USIZE( value_buf ); - UChar* value = value_buf; + UChar value_buf[64]; + int32_t length = USIZE( value_buf ); + UChar* value = value_buf; FORMATTER_METHOD_INIT_VARS; /* Parse parameters. */ @@ -388,7 +388,7 @@ PHP_FUNCTION( numfmt_set_pattern ) { char* value = NULL; size_t value_len = 0; - int slength = 0; + int32_t slength = 0; UChar* svalue = NULL; FORMATTER_METHOD_INIT_VARS; diff --git a/ext/intl/formatter/formatter_format.c b/ext/intl/formatter/formatter_format.c index b852e54b3e..a46efd9660 100644 --- a/ext/intl/formatter/formatter_format.c +++ b/ext/intl/formatter/formatter_format.c @@ -36,7 +36,7 @@ PHP_FUNCTION( numfmt_format ) zend_long type = FORMAT_TYPE_DEFAULT; UChar format_buf[32]; UChar* formatted = format_buf; - int formatted_len = USIZE(format_buf); + int32_t formatted_len = USIZE(format_buf); FORMATTER_METHOD_INIT_VARS; /* Parse parameters. */ @@ -139,11 +139,11 @@ PHP_FUNCTION( numfmt_format_currency ) double number; UChar format_buf[32]; UChar* formatted = format_buf; - int formatted_len = USIZE(format_buf); + int32_t formatted_len = USIZE(format_buf); char* currency = NULL; - size_t currency_len = 0; + size_t currency_len = 0; UChar* scurrency = NULL; - int scurrency_len = 0; + int32_t scurrency_len = 0; FORMATTER_METHOD_INIT_VARS; /* Parse parameters. */ diff --git a/ext/intl/formatter/formatter_main.c b/ext/intl/formatter/formatter_main.c index 067f3bd82b..59629a68f9 100644 --- a/ext/intl/formatter/formatter_main.c +++ b/ext/intl/formatter/formatter_main.c @@ -29,10 +29,10 @@ static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS) { const char* locale; char* pattern = NULL; - size_t locale_len = 0, pattern_len = 0; - zend_long style; + size_t locale_len = 0, pattern_len = 0; + zend_long style; UChar* spattern = NULL; - int spattern_len = 0; + int32_t spattern_len = 0; FORMATTER_METHOD_INIT_VARS; /* Parse parameters. */ diff --git a/ext/intl/formatter/formatter_parse.c b/ext/intl/formatter/formatter_parse.c index b2af74a2e0..43f6780e57 100644 --- a/ext/intl/formatter/formatter_parse.c +++ b/ext/intl/formatter/formatter_parse.c @@ -38,7 +38,7 @@ PHP_FUNCTION( numfmt_parse ) { zend_long type = FORMAT_TYPE_DOUBLE; UChar* sstr = NULL; - int sstr_len = 0; + int32_t sstr_len = 0; char* str = NULL; size_t str_len; int32_t val32, position = 0; @@ -128,9 +128,9 @@ PHP_FUNCTION( numfmt_parse_currency ) double number; UChar currency[5] = {0}; UChar* sstr = NULL; - int sstr_len = 0; + int32_t sstr_len = 0; char *currency_str = NULL; - int currency_len = 0; + size_t currency_len = 0; char *str; size_t str_len; int32_t* position_p = NULL; diff --git a/ext/intl/grapheme/grapheme_string.c b/ext/intl/grapheme/grapheme_string.c index d5a33fe663..91cc1802ae 100644 --- a/ext/intl/grapheme/grapheme_string.c +++ b/ext/intl/grapheme/grapheme_string.c @@ -54,29 +54,27 @@ void grapheme_register_constants( INIT_FUNC_ARGS ) Get number of graphemes in a string */ PHP_FUNCTION(grapheme_strlen) { - unsigned char* string; + char* string; size_t string_len; UChar* ustring = NULL; int ustring_len = 0; - int ret_len; + zend_long ret_len; UErrorCode status; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", (char **)&string, &string_len) == FAILURE) { - + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &string, &string_len) == FAILURE) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_strlen: unable to parse input param", 0 ); - RETURN_FALSE; } - ret_len = grapheme_ascii_check(string, string_len); + ret_len = grapheme_ascii_check((unsigned char *)string, string_len); if ( ret_len >= 0 ) - RETURN_LONG(ret_len); + RETURN_LONG(string_len); /* convert the string to UTF-16. */ status = U_ZERO_ERROR; - intl_convert_utf8_to_utf16(&ustring, &ustring_len, (char*) string, string_len, &status ); + intl_convert_utf8_to_utf16(&ustring, &ustring_len, string, string_len, &status ); if ( U_FAILURE( status ) ) { /* Set global error code. */ @@ -108,25 +106,21 @@ PHP_FUNCTION(grapheme_strlen) Find position of first occurrence of a string within another */ PHP_FUNCTION(grapheme_strpos) { - unsigned char *haystack, *needle; + char *haystack, *needle; size_t haystack_len, needle_len; - unsigned char *found; + const char *found; zend_long loffset = 0; int32_t offset = 0; - int ret_pos; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|l", (char **)&haystack, &haystack_len, (char **)&needle, &needle_len, &loffset) == FAILURE) { + zend_long ret_pos; + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|l", &haystack, &haystack_len, &needle, &needle_len, &loffset) == FAILURE) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_strpos: unable to parse input param", 0 ); - RETURN_FALSE; } if ( OUTSIDE_STRING(loffset, haystack_len) ) { - intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_strpos: Offset not contained in string", 1 ); - RETURN_FALSE; } @@ -136,9 +130,7 @@ PHP_FUNCTION(grapheme_strpos) /* the offset is 'grapheme count offset' so it still might be invalid - we'll check it later */ if (needle_len == 0) { - intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_strpos: Empty delimiter", 1 ); - RETURN_FALSE; } @@ -146,7 +138,7 @@ PHP_FUNCTION(grapheme_strpos) /* quick check to see if the string might be there * I realize that 'offset' is 'grapheme count offset' but will work in spite of that */ - found = (unsigned char *)php_memnstr((char *)haystack + offset, (char *)needle, needle_len, (char *)haystack + haystack_len); + found = php_memnstr(haystack + offset, needle, needle_len, haystack + haystack_len); /* if it isn't there the we are done */ if (!found) { @@ -154,8 +146,7 @@ PHP_FUNCTION(grapheme_strpos) } /* if it is there, and if the haystack is ascii, we are all done */ - if ( grapheme_ascii_check(haystack, haystack_len) >= 0 ) { - + if ( grapheme_ascii_check((unsigned char *)haystack, haystack_len) >= 0 ) { RETURN_LONG(found - haystack); } @@ -175,26 +166,22 @@ PHP_FUNCTION(grapheme_strpos) Find position of first occurrence of a string within another, ignoring case differences */ PHP_FUNCTION(grapheme_stripos) { - unsigned char *haystack, *needle, *haystack_dup, *needle_dup; + char *haystack, *needle, *haystack_dup, *needle_dup; size_t haystack_len, needle_len; - unsigned char *found; + const char *found; zend_long loffset = 0; int32_t offset = 0; - int ret_pos; + zend_long ret_pos; int is_ascii; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|l", (char **)&haystack, &haystack_len, (char **)&needle, &needle_len, &loffset) == FAILURE) { - + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|l", &haystack, &haystack_len, &needle, &needle_len, &loffset) == FAILURE) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_stripos: unable to parse input param", 0 ); - RETURN_FALSE; } if ( OUTSIDE_STRING(loffset, haystack_len) ) { - intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_stripos: Offset not contained in string", 1 ); - RETURN_FALSE; } @@ -204,22 +191,20 @@ PHP_FUNCTION(grapheme_stripos) /* the offset is 'grapheme count offset' so it still might be invalid - we'll check it later */ if (needle_len == 0) { - intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_stripos: Empty delimiter", 1 ); - RETURN_FALSE; } - is_ascii = ( grapheme_ascii_check(haystack, haystack_len) >= 0 ); + is_ascii = ( grapheme_ascii_check((unsigned char*)haystack, haystack_len) >= 0 ); if ( is_ascii ) { - needle_dup = (unsigned char *)estrndup((char *)needle, needle_len); - php_strtolower((char *)needle_dup, needle_len); - haystack_dup = (unsigned char *)estrndup((char *)haystack, haystack_len); - php_strtolower((char *)haystack_dup, haystack_len); + needle_dup = estrndup(needle, needle_len); + php_strtolower(needle_dup, needle_len); + haystack_dup = estrndup(haystack, haystack_len); + php_strtolower(haystack_dup, haystack_len); - found = (unsigned char*) php_memnstr((char *)haystack_dup + offset, (char *)needle_dup, needle_len, (char *)haystack_dup + haystack_len); + found = php_memnstr(haystack_dup + offset, needle_dup, needle_len, haystack_dup + haystack_len); efree(haystack_dup); efree(needle_dup); @@ -229,7 +214,7 @@ PHP_FUNCTION(grapheme_stripos) } /* if needle was ascii too, we are all done, otherwise we need to try using Unicode to see what we get */ - if ( grapheme_ascii_check(needle, needle_len) >= 0 ) { + if ( grapheme_ascii_check((unsigned char *)needle, needle_len) >= 0 ) { RETURN_FALSE; } } @@ -250,25 +235,21 @@ PHP_FUNCTION(grapheme_stripos) Find position of last occurrence of a string within another */ PHP_FUNCTION(grapheme_strrpos) { - unsigned char *haystack, *needle; + char *haystack, *needle; size_t haystack_len, needle_len; zend_long loffset = 0; int32_t offset = 0; - int32_t ret_pos; + zend_long ret_pos; int is_ascii; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|l", (char **)&haystack, &haystack_len, (char **)&needle, &needle_len, &loffset) == FAILURE) { - + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|l", &haystack, &haystack_len, &needle, &needle_len, &loffset) == FAILURE) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_strrpos: unable to parse input param", 0 ); - RETURN_FALSE; } if ( OUTSIDE_STRING(loffset, haystack_len) ) { - intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_strpos: Offset not contained in string", 1 ); - RETURN_FALSE; } @@ -278,26 +259,23 @@ PHP_FUNCTION(grapheme_strrpos) /* the offset is 'grapheme count offset' so it still might be invalid - we'll check it later */ if (needle_len == 0) { - intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_strpos: Empty delimiter", 1 ); - RETURN_FALSE; } - is_ascii = grapheme_ascii_check(haystack, haystack_len) >= 0; + is_ascii = grapheme_ascii_check((unsigned char *)haystack, haystack_len) >= 0; if ( is_ascii ) { ret_pos = grapheme_strrpos_ascii(haystack, haystack_len, needle, needle_len, offset); - if ( ret_pos >= 0 ) { RETURN_LONG(ret_pos); } /* if the needle was ascii too, we are done */ - if ( grapheme_ascii_check(needle, needle_len) >= 0 ) { + if ( grapheme_ascii_check((unsigned char *)needle, needle_len) >= 0 ) { RETURN_FALSE; } @@ -320,25 +298,21 @@ PHP_FUNCTION(grapheme_strrpos) Find position of last occurrence of a string within another, ignoring case */ PHP_FUNCTION(grapheme_strripos) { - unsigned char *haystack, *needle; + char *haystack, *needle; size_t haystack_len, needle_len; zend_long loffset = 0; int32_t offset = 0; - int32_t ret_pos; + zend_long ret_pos; int is_ascii; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|l", (char **)&haystack, &haystack_len, (char **)&needle, &needle_len, &loffset) == FAILURE) { - + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|l", &haystack, &haystack_len, &needle, &needle_len, &loffset) == FAILURE) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_strrpos: unable to parse input param", 0 ); - RETURN_FALSE; } if ( OUTSIDE_STRING(loffset, haystack_len) ) { - intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_strpos: Offset not contained in string", 1 ); - RETURN_FALSE; } @@ -348,21 +322,19 @@ PHP_FUNCTION(grapheme_strripos) /* the offset is 'grapheme count offset' so it still might be invalid - we'll check it later */ if (needle_len == 0) { - intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_strpos: Empty delimiter", 1 ); - RETURN_FALSE; } - is_ascii = grapheme_ascii_check(haystack, haystack_len) >= 0; + is_ascii = grapheme_ascii_check((unsigned char *)haystack, haystack_len) >= 0; if ( is_ascii ) { - unsigned char *needle_dup, *haystack_dup; + char *needle_dup, *haystack_dup; - needle_dup = (unsigned char *)estrndup((char *)needle, needle_len); - php_strtolower((char *)needle_dup, needle_len); - haystack_dup = (unsigned char *)estrndup((char *)haystack, haystack_len); - php_strtolower((char *)haystack_dup, haystack_len); + needle_dup = estrndup(needle, needle_len); + php_strtolower(needle_dup, needle_len); + haystack_dup = estrndup(haystack, haystack_len); + php_strtolower(haystack_dup, haystack_len); ret_pos = grapheme_strrpos_ascii(haystack_dup, haystack_len, needle_dup, needle_len, offset); @@ -375,7 +347,7 @@ PHP_FUNCTION(grapheme_strripos) /* if the needle was ascii too, we are done */ - if ( grapheme_ascii_check(needle, needle_len) >= 0 ) { + if ( grapheme_ascii_check((unsigned char *)needle, needle_len) >= 0 ) { RETURN_FALSE; } @@ -398,11 +370,11 @@ PHP_FUNCTION(grapheme_strripos) Returns part of a string */ PHP_FUNCTION(grapheme_substr) { - unsigned char *str, *sub_str; + char *str, *sub_str; UChar *ustr; size_t str_len; int32_t ustr_len; - int32_t sub_str_len; + size_t sub_str_len; zend_long lstart = 0, length = 0; int32_t start = 0; int iter_val; @@ -411,42 +383,50 @@ PHP_FUNCTION(grapheme_substr) UBreakIterator* bi = NULL; int sub_str_start_pos, sub_str_end_pos; int32_t (*iter_func)(UBreakIterator *); + int no_length = 1; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|l", (char **)&str, &str_len, &lstart, &length) == FAILURE) { - + if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|l!", (char **)&str, &str_len, &lstart, &length, &no_length) == FAILURE) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_substr: unable to parse input param", 0 ); - RETURN_FALSE; } - if ( OUTSIDE_STRING(lstart, str_len) ) { - + if ( OUTSIDE_STRING(lstart, str_len)) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_substr: start not contained in string", 1 ); - RETURN_FALSE; } /* we checked that it will fit: */ start = (int32_t) lstart; + if(no_length) { + length = str_len; + } + + if(length < INT32_MIN) { + length = INT32_MIN; + } else if(length > INT32_MAX) { + length = INT32_MAX; + } + /* the offset is 'grapheme count offset' so it still might be invalid - we'll check it later */ - if ( grapheme_ascii_check(str, str_len) >= 0 ) { - grapheme_substr_ascii((char *)str, str_len, start, length, ZEND_NUM_ARGS(), (char **) &sub_str, &sub_str_len); + if ( grapheme_ascii_check((unsigned char *)str, str_len) >= 0 ) { + int32_t asub_str_len; + grapheme_substr_ascii(str, str_len, start, (int32_t)length, &sub_str, &asub_str_len); if ( NULL == sub_str ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_substr: invalid parameters", 1 ); RETURN_FALSE; } - RETURN_STRINGL(((char *)sub_str), sub_str_len); + RETURN_STRINGL(sub_str, asub_str_len); } ustr = NULL; ustr_len = 0; status = U_ZERO_ERROR; - intl_convert_utf8_to_utf16(&ustr, &ustr_len, (char *)str, str_len, &status); + intl_convert_utf8_to_utf16(&ustr, &ustr_len, str, str_len, &status); if ( U_FAILURE( status ) ) { /* Set global error code. */ @@ -501,14 +481,15 @@ PHP_FUNCTION(grapheme_substr) RETURN_FALSE; } - if (ZEND_NUM_ARGS() <= 2) { + /* OK to convert here since if str_len were big, convert above would fail */ + if (length >= (int32_t)str_len) { - /* no length supplied, return the rest of the string */ + /* no length supplied or length is too big, return the rest of the string */ sub_str = NULL; sub_str_len = 0; status = U_ZERO_ERROR; - intl_convert_utf16_to_utf8((char **)&sub_str, &sub_str_len, ustr + sub_str_start_pos, ustr_len - sub_str_start_pos, &status); + intl_convert_utf16_to_utf8(&sub_str, &sub_str_len, ustr + sub_str_start_pos, ustr_len - sub_str_start_pos, &status); if (ustr) { efree( ustr ); @@ -530,7 +511,7 @@ PHP_FUNCTION(grapheme_substr) } /* return the allocated string, not a duplicate */ - RETVAL_STRINGL(((char *)sub_str), sub_str_len); + RETVAL_STRINGL(sub_str, sub_str_len); //??? efree(sub_str); return; @@ -591,7 +572,7 @@ PHP_FUNCTION(grapheme_substr) sub_str = NULL; status = U_ZERO_ERROR; - intl_convert_utf16_to_utf8((char **)&sub_str, &sub_str_len, ustr + sub_str_start_pos, ( sub_str_end_pos - sub_str_start_pos ), &status); + intl_convert_utf16_to_utf8(&sub_str, &sub_str_len, ustr + sub_str_start_pos, ( sub_str_end_pos - sub_str_start_pos ), &status); efree( ustr ); @@ -609,7 +590,7 @@ PHP_FUNCTION(grapheme_substr) } /* return the allocated string, not a duplicate */ - RETVAL_STRINGL(((char *)sub_str), sub_str_len); + RETVAL_STRINGL(sub_str, sub_str_len); //???? efree(sub_str); @@ -619,12 +600,13 @@ PHP_FUNCTION(grapheme_substr) /* {{{ strstr_common_handler */ static void strstr_common_handler(INTERNAL_FUNCTION_PARAMETERS, int f_ignore_case) { - unsigned char *haystack, *needle, *found; + char *haystack, *needle; + const char *found; size_t haystack_len, needle_len; - int ret_pos, uchar_pos; + int32_t ret_pos, uchar_pos; zend_bool part = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|b", (char **)&haystack, &haystack_len, (char **)&needle, &needle_len, &part) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|b", &haystack, &haystack_len, &needle, &needle_len, &part) == FAILURE) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_strstr: unable to parse input param", 0 ); @@ -645,7 +627,7 @@ static void strstr_common_handler(INTERNAL_FUNCTION_PARAMETERS, int f_ignore_cas /* ASCII optimization: quick check to see if the string might be there * I realize that 'offset' is 'grapheme count offset' but will work in spite of that */ - found = (unsigned char *)php_memnstr((char *)haystack, (char *)needle, needle_len, (char *)haystack + haystack_len); + found = php_memnstr(haystack, needle, needle_len, haystack + haystack_len); /* if it isn't there the we are done */ if ( !found ) { @@ -653,13 +635,13 @@ static void strstr_common_handler(INTERNAL_FUNCTION_PARAMETERS, int f_ignore_cas } /* if it is there, and if the haystack is ascii, we are all done */ - if ( grapheme_ascii_check(haystack, haystack_len) >= 0 ) { + if ( grapheme_ascii_check((unsigned char *)haystack, haystack_len) >= 0 ) { size_t found_offset = found - haystack; if (part) { - RETURN_STRINGL(((char *)haystack) , found_offset); + RETURN_STRINGL(haystack, found_offset); } else { - RETURN_STRINGL(((char *)found), haystack_len - found_offset); + RETURN_STRINGL(found, haystack_len - found_offset); } } @@ -678,10 +660,9 @@ static void strstr_common_handler(INTERNAL_FUNCTION_PARAMETERS, int f_ignore_cas U8_FWD_N(haystack, ret_pos, haystack_len, uchar_pos); if (part) { - RETURN_STRINGL(((char *)haystack), ret_pos); - } - else { - RETURN_STRINGL(((char *)haystack) + ret_pos, haystack_len - ret_pos); + RETURN_STRINGL(haystack, ret_pos); + } else { + RETURN_STRINGL(haystack + ret_pos, haystack_len - ret_pos); } } @@ -815,7 +796,7 @@ static grapheme_extract_iter grapheme_extract_iters[] = { Function to extract a sequence of default grapheme clusters */ PHP_FUNCTION(grapheme_extract) { - unsigned char *str, *pstr; + char *str, *pstr; UChar *ustr; size_t str_len; int32_t ustr_len; @@ -829,11 +810,9 @@ PHP_FUNCTION(grapheme_extract) int ret_pos; zval *next = NULL; /* return offset of next part of the string */ - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|llz", (char **)&str, &str_len, &size, &extract_type, &lstart, &next) == FAILURE) { - + if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|llz", &str, &str_len, &size, &extract_type, &lstart, &next) == FAILURE) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_extract: unable to parse input param", 0 ); - RETURN_FALSE; } @@ -841,10 +820,8 @@ PHP_FUNCTION(grapheme_extract) if ( !Z_ISREF_P(next) ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_extract: 'next' was not passed by reference", 0 ); - RETURN_FALSE; - } - else { + } else { ZVAL_DEREF(next); /* initialize next */ SEPARATE_ZVAL(next); @@ -854,10 +831,8 @@ PHP_FUNCTION(grapheme_extract) } if ( extract_type < GRAPHEME_EXTRACT_TYPE_MIN || extract_type > GRAPHEME_EXTRACT_TYPE_MAX ) { - intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_extract: unknown extract type param", 0 ); - RETURN_FALSE; } @@ -881,7 +856,7 @@ PHP_FUNCTION(grapheme_extract) /* just in case pstr points in the middle of a character, move forward to the start of the next char */ if ( !UTF8_IS_SINGLE(*pstr) && !U8_IS_LEAD(*pstr) ) { - unsigned char *str_end = str + str_len; + char *str_end = str + str_len; while ( !UTF8_IS_SINGLE(*pstr) && !U8_IS_LEAD(*pstr) ) { pstr++; @@ -900,19 +875,19 @@ PHP_FUNCTION(grapheme_extract) (size + 1 because the size-th character might be the beginning of a grapheme cluster) */ - if ( -1 != grapheme_ascii_check(pstr, size + 1 < str_len ? size + 1 : str_len ) ) { - zend_long nsize = ( size < str_len ? size : str_len ); + if ( -1 != grapheme_ascii_check((unsigned char *)pstr, MIN(size + 1, str_len)) ) { + size_t nsize = MIN(size, str_len); if ( NULL != next ) { ZVAL_LONG(next, start+nsize); } - RETURN_STRINGL(((char *)pstr), nsize); + RETURN_STRINGL(pstr, nsize); } /* convert the strings to UTF-16. */ ustr = NULL; ustr_len = 0; status = U_ZERO_ERROR; - intl_convert_utf8_to_utf16(&ustr, &ustr_len, (char *)pstr, str_len, &status ); + intl_convert_utf8_to_utf16(&ustr, &ustr_len, pstr, str_len, &status ); if ( U_FAILURE( status ) ) { /* Set global error code. */ @@ -937,8 +912,8 @@ PHP_FUNCTION(grapheme_extract) can't back up. So, we will not do anything. */ /* now we need to find the end of the chunk the user wants us to return */ - - ret_pos = (*grapheme_extract_iters[extract_type])(bi, size, pstr, str_len); + /* it's ok to convert str_len to in32_t since if it were too big intl_convert_utf8_to_utf16 above would fail */ + ret_pos = (*grapheme_extract_iters[extract_type])(bi, size, (unsigned char *)pstr, (int32_t)str_len); if (ustr) { efree(ustr); diff --git a/ext/intl/grapheme/grapheme_util.c b/ext/intl/grapheme/grapheme_util.c index bb4ecac084..c3db4aabdf 100644 --- a/ext/intl/grapheme/grapheme_util.c +++ b/ext/intl/grapheme/grapheme_util.c @@ -49,25 +49,27 @@ grapheme_close_global_iterator( void ) /* }}} */ /* {{{ grapheme_substr_ascii f='from' - starting point, l='length' */ -void grapheme_substr_ascii(char *str, int str_len, int f, int l, int argc, char **sub_str, int *sub_str_len) +void grapheme_substr_ascii(char *str, size_t str_len, int32_t f, int32_t l, char **sub_str, int32_t *sub_str_len) { + int32_t str_len2 = (int32_t)str_len; /* in order to avoid signed/unsigned problems */ *sub_str = NULL; - if (argc > 2) { - if ((l < 0 && -l > str_len)) { - return; - } else if (l > str_len) { - l = str_len; - } - } else { - l = str_len; + if(str_len > INT32_MAX) { + /* We can not return long strings from ICU functions, so we won't here too */ + return; } - if (f > str_len || (f < 0 && -f > str_len)) { + if ((l < 0 && -l > str_len2)) { return; + } else if (l > 0 && l > str_len2) { + l = str_len2; } - if (l < 0 && (l + str_len - f) < 0) { + if (f > str_len2 || (f < 0 && -f > str_len2)) { + return; + } + + if (l < 0 && str_len2 < f - l) { return; } @@ -75,7 +77,7 @@ void grapheme_substr_ascii(char *str, int str_len, int f, int l, int argc, char * of the string */ if (f < 0) { - f = str_len + f; + f = str_len2 + f; if (f < 0) { f = 0; } @@ -86,17 +88,17 @@ void grapheme_substr_ascii(char *str, int str_len, int f, int l, int argc, char * needed to stop that many chars from the end of the string */ if (l < 0) { - l = (str_len - f) + l; + l = (str_len2 - f) + l; if (l < 0) { l = 0; } } - if (f >= str_len) { + if (f >= str_len2) { return; } - if ((f + l) > str_len) { + if ((f + l) > str_len2) { l = str_len - f; } @@ -128,7 +130,7 @@ void grapheme_substr_ascii(char *str, int str_len, int f, int l, int argc, char /* {{{ grapheme_strpos_utf16 - strrpos using utf16*/ -int grapheme_strpos_utf16(unsigned char *haystack, int32_t haystack_len, unsigned char*needle, int32_t needle_len, int32_t offset, int32_t *puchar_pos, int f_ignore_case, int last) +int32_t grapheme_strpos_utf16(char *haystack, size_t haystack_len, char *needle, size_t needle_len, int32_t offset, int32_t *puchar_pos, int f_ignore_case, int last) { UChar *uhaystack = NULL, *uneedle = NULL; int32_t uhaystack_len = 0, uneedle_len = 0, char_pos, ret_pos, offset_pos = 0; @@ -144,12 +146,12 @@ int grapheme_strpos_utf16(unsigned char *haystack, int32_t haystack_len, unsigne /* convert the strings to UTF-16. */ status = U_ZERO_ERROR; - intl_convert_utf8_to_utf16(&uhaystack, &uhaystack_len, (char *) haystack, haystack_len, &status ); + intl_convert_utf8_to_utf16(&uhaystack, &uhaystack_len, haystack, haystack_len, &status ); STRPOS_CHECK_STATUS(status, "Error converting input string to UTF-16"); status = U_ZERO_ERROR; - intl_convert_utf8_to_utf16(&uneedle, &uneedle_len, (char *) needle, needle_len, &status ); - STRPOS_CHECK_STATUS(status, "Error converting input string to UTF-16"); + intl_convert_utf8_to_utf16(&uneedle, &uneedle_len, needle, needle_len, &status ); + STRPOS_CHECK_STATUS(status, "Error converting needle string to UTF-16"); /* get a pointer to the haystack taking into account the offset */ status = U_ZERO_ERROR; @@ -217,7 +219,7 @@ int grapheme_strpos_utf16(unsigned char *haystack, int32_t haystack_len, unsigne /* }}} */ /* {{{ grapheme_ascii_check: ASCII check */ -int grapheme_ascii_check(const unsigned char *day, int32_t len) +zend_long grapheme_ascii_check(const unsigned char *day, size_t len) { int ret_len = len; while ( len-- ) { @@ -231,7 +233,7 @@ int grapheme_ascii_check(const unsigned char *day, int32_t len) /* }}} */ /* {{{ grapheme_split_string: find and optionally return grapheme boundaries */ -int grapheme_split_string(const UChar *text, int32_t text_length, int boundary_array[], int boundary_array_len ) +int32_t grapheme_split_string(const UChar *text, int32_t text_length, int boundary_array[], int boundary_array_len ) { unsigned char u_break_iterator_buffer[U_BRK_SAFECLONE_BUFFERSIZE]; UErrorCode status = U_ZERO_ERROR; @@ -293,7 +295,7 @@ int32_t grapheme_count_graphemes(UBreakIterator *bi, UChar *string, int32_t stri /* {{{ grapheme_get_haystack_offset - bump the haystack pointer based on the grapheme count offset */ -int grapheme_get_haystack_offset(UBreakIterator* bi, int32_t offset) +int32_t grapheme_get_haystack_offset(UBreakIterator* bi, int32_t offset) { int32_t pos; int32_t (*iter_op)(UBreakIterator* bi); @@ -333,10 +335,10 @@ int grapheme_get_haystack_offset(UBreakIterator* bi, int32_t offset) /* }}} */ /* {{{ grapheme_strrpos_ascii: borrowed from the php ext/standard/string.c */ - int32_t -grapheme_strrpos_ascii(unsigned char *haystack, int32_t haystack_len, unsigned char *needle, int32_t needle_len, int32_t offset) + zend_long +grapheme_strrpos_ascii(char *haystack, size_t haystack_len, char *needle, size_t needle_len, int32_t offset) { - unsigned char *p, *e; + char *p, *e; if (offset >= 0) { p = haystack + offset; diff --git a/ext/intl/grapheme/grapheme_util.h b/ext/intl/grapheme/grapheme_util.h index 99021287fa..492b19bb7f 100644 --- a/ext/intl/grapheme/grapheme_util.h +++ b/ext/intl/grapheme/grapheme_util.h @@ -23,23 +23,20 @@ /* get_break_interator: get a break iterator from the global structure */ UBreakIterator* grapheme_get_break_iterator(void *stack_buffer, UErrorCode *status ); -void grapheme_substr_ascii(char *str, int32_t str_len, int32_t f, int32_t l, int argc, char **sub_str, int *sub_str_len); +zend_long grapheme_ascii_check(const unsigned char *day, size_t len); +void grapheme_substr_ascii(char *str, size_t str_len, int32_t f, int32_t l, char **sub_str, int32_t *sub_str_len); +zend_long grapheme_strrpos_ascii(char *haystack, size_t haystack_len, char *needle, size_t needle_len, int32_t offset); -int grapheme_strrpos_utf16(unsigned char *haystack, int32_t haystack_len, unsigned char*needle, int32_t needle_len, int32_t offset, int f_ignore_case); +int32_t grapheme_strrpos_utf16(char *haystack, size_t haystack_len, char *needle, size_t needle_len, int32_t offset, int f_ignore_case); +int32_t grapheme_strpos_utf16(char *haystack, size_t haystack_len, char *needle, size_t needle_len, int32_t offset, int *puchar_pos, int f_ignore_case, int last); -int grapheme_strpos_utf16(unsigned char *haystack, int32_t haystack_len, unsigned char*needle, int32_t needle_len, int32_t offset, int *puchar_pos, int f_ignore_case, int last); - -int grapheme_ascii_check(const unsigned char *day, int32_t len); - -int grapheme_split_string(const UChar *text, int32_t text_length, int boundary_array[], int boundary_array_len ); +int32_t grapheme_split_string(const UChar *text, int32_t text_length, int boundary_array[], int boundary_array_len ); int32_t grapheme_count_graphemes(UBreakIterator *bi, UChar *string, int32_t string_len); inline void *grapheme_memrchr_grapheme(const void *s, int c, int32_t n); -int grapheme_get_haystack_offset(UBreakIterator* bi, int32_t offset); - -int32_t grapheme_strrpos_ascii(unsigned char *haystack, int32_t haystack_len, unsigned char *needle, int32_t needle_len, int32_t offset); +int32_t grapheme_get_haystack_offset(UBreakIterator* bi, int32_t offset); UBreakIterator* grapheme_get_break_iterator(void *stack_buffer, UErrorCode *status ); diff --git a/ext/intl/idn/idn.c b/ext/intl/idn/idn.c index 0848be94a7..1bd9f6d2a3 100644 --- a/ext/intl/idn/idn.c +++ b/ext/intl/idn/idn.c @@ -134,7 +134,7 @@ static inline void php_intl_bad_args(const char *msg, int mode) #ifdef HAVE_46_API static void php_intl_idn_to_46(INTERNAL_FUNCTION_PARAMETERS, - const char *domain, int domain_len, uint32_t option, int mode, zval *idna_info) + const char *domain, int32_t domain_len, uint32_t option, int mode, zval *idna_info) { UErrorCode status = U_ZERO_ERROR; UIDNA *uts46; @@ -152,10 +152,10 @@ static void php_intl_idn_to_46(INTERNAL_FUNCTION_PARAMETERS, } if (mode == INTL_IDN_TO_ASCII) { - len = uidna_nameToASCII_UTF8(uts46, domain, (int32_t)domain_len, + len = uidna_nameToASCII_UTF8(uts46, domain, domain_len, buffer->val, buffer_capac, &info, &status); } else { - len = uidna_nameToUnicodeUTF8(uts46, domain, (int32_t)domain_len, + len = uidna_nameToUnicodeUTF8(uts46, domain, domain_len, buffer->val, buffer_capac, &info, &status); } if (php_intl_idn_check_status(status, "failed to convert name", @@ -202,13 +202,13 @@ static void php_intl_idn_to_46(INTERNAL_FUNCTION_PARAMETERS, #endif static void php_intl_idn_to(INTERNAL_FUNCTION_PARAMETERS, - const char *domain, int domain_len, uint32_t option, int mode) + const char *domain, int32_t domain_len, uint32_t option, int mode) { UChar* ustring = NULL; int ustring_len = 0; UErrorCode status; char *converted_utf8; - int32_t converted_utf8_len; + size_t converted_utf8_len; UChar converted[MAXPATHLEN]; int32_t converted_ret_len; @@ -256,7 +256,7 @@ static void php_intl_idn_to(INTERNAL_FUNCTION_PARAMETERS, } /* return the allocated string, not a duplicate */ - RETVAL_STRINGL(((char *)converted_utf8), converted_utf8_len); + RETVAL_STRINGL(converted_utf8, converted_utf8_len); //???? efree(converted_utf8); } @@ -315,11 +315,11 @@ static void php_intl_idn_handoff(INTERNAL_FUNCTION_PARAMETERS, int mode) if (variant == INTL_IDN_VARIANT_2003) { php_intl_idn_to(INTERNAL_FUNCTION_PARAM_PASSTHRU, - domain, domain_len, (uint32_t)option, mode); + domain, (int32_t)domain_len, (uint32_t)option, mode); } #ifdef HAVE_46_API else { - php_intl_idn_to_46(INTERNAL_FUNCTION_PARAM_PASSTHRU, domain, domain_len, + php_intl_idn_to_46(INTERNAL_FUNCTION_PARAM_PASSTHRU, domain, (int32_t)domain_len, (uint32_t)option, mode, idna_info); } #endif diff --git a/ext/intl/intl_convert.c b/ext/intl/intl_convert.c index 50a742082f..51537062f5 100644 --- a/ext/intl/intl_convert.c +++ b/ext/intl/intl_convert.c @@ -35,6 +35,10 @@ * In this case the buffer will be used to store the converted string to, * and may be resized (made larger) if needed. * + * Note that ICU uses int32_t as string length and PHP uses size_t. While + * it is not likely in practical situations to have strings longer than + * INT32_MAX, these are different types and need to be handled carefully. + * * @param target Where to place the result. * @param target_len Result length. * @param source String to convert. @@ -44,8 +48,8 @@ * @return void This function does not return anything. */ void intl_convert_utf8_to_utf16( - UChar** target, int* target_len, - const char* src, int src_len, + UChar** target, int32_t* target_len, + const char* src, size_t src_len, UErrorCode* status ) { UChar* dst_buf = NULL; @@ -57,7 +61,13 @@ void intl_convert_utf8_to_utf16( */ *status = U_ZERO_ERROR; - u_strFromUTF8( *target, *target_len, &dst_len, src, src_len, status ); + if(src_len > INT32_MAX) { + /* we can not fit this string */ + *status = U_BUFFER_OVERFLOW_ERROR; + return; + } + + u_strFromUTF8( *target, *target_len, &dst_len, src, (int32_t)src_len, status ); if( *status == U_ZERO_ERROR ) { @@ -108,8 +118,8 @@ void intl_convert_utf8_to_utf16( * @return void This function does not return anything. */ void intl_convert_utf16_to_utf8( - char** target, int* target_len, - const UChar* src, int src_len, + char** target, size_t* target_len, + const UChar* src, int32_t src_len, UErrorCode* status ) { char* dst_buf = NULL; @@ -143,7 +153,7 @@ void intl_convert_utf16_to_utf8( dst_buf[dst_len] = 0; *target = dst_buf; - *target_len = dst_len; + *target_len = (size_t)dst_len; } /* }}} */ diff --git a/ext/intl/intl_convert.h b/ext/intl/intl_convert.h index 952d765c52..2885890ef3 100644 --- a/ext/intl/intl_convert.h +++ b/ext/intl/intl_convert.h @@ -21,13 +21,13 @@ #include <unicode/ustring.h> void intl_convert_utf8_to_utf16( - UChar** target, int* target_len, - const char* src, int src_len, + UChar** target, int32_t* target_len, + const char* src, size_t src_len, UErrorCode* status ); void intl_convert_utf16_to_utf8( - char** target, int* target_len, - const UChar* src, int src_len, + char** target, size_t* target_len, + const UChar* src, int32_t src_len, UErrorCode* status ); #endif // INTL_CONVERT_H diff --git a/ext/intl/intl_convertcpp.cpp b/ext/intl/intl_convertcpp.cpp index f52348bc25..3507737616 100644 --- a/ext/intl/intl_convertcpp.cpp +++ b/ext/intl/intl_convertcpp.cpp @@ -25,11 +25,16 @@ extern "C" { } /* {{{ intl_stringFromChar */ -int intl_stringFromChar(UnicodeString &ret, char *str, int32_t str_len, UErrorCode *status) +int intl_stringFromChar(UnicodeString &ret, char *str, size_t str_len, UErrorCode *status) { + if(str_len > INT32_MAX) { + *status = U_BUFFER_OVERFLOW_ERROR; + ret.setToBogus(); + return FAILURE; + } //the number of UTF-16 code units is not larger than that of UTF-8 code //units, + 1 for the terminator - int32_t capacity = str_len + 1; + int32_t capacity = (int32_t)str_len + 1; //no check necessary -- if NULL will fail ahead UChar *utf16 = ret.getBuffer(capacity); @@ -51,7 +56,7 @@ int intl_stringFromChar(UnicodeString &ret, char *str, int32_t str_len, UErrorCo * faster than doing intl_convert_utf16_to_utf8(&res, &res_len, * from.getBuffer(), from.length(), &status), * but consumes more memory */ -int intl_charFromString(const UnicodeString &from, char **res, int *res_len, UErrorCode *status) +int intl_charFromString(const UnicodeString &from, char **res, size_t *res_len, UErrorCode *status) { if (from.isBogus()) { return FAILURE; @@ -82,7 +87,7 @@ int intl_charFromString(const UnicodeString &from, char **res, int *res_len, UEr return FAILURE; } (*res)[actual_len] = '\0'; - *res_len = (int)actual_len; + *res_len = actual_len; return SUCCESS; } diff --git a/ext/intl/intl_convertcpp.h b/ext/intl/intl_convertcpp.h index fc2242a6b8..c4b689166d 100644 --- a/ext/intl/intl_convertcpp.h +++ b/ext/intl/intl_convertcpp.h @@ -25,8 +25,8 @@ #include <unicode/unistr.h> -int intl_stringFromChar(UnicodeString &ret, char *str, int32_t str_len, UErrorCode *status); +int intl_stringFromChar(UnicodeString &ret, char *str, size_t str_len, UErrorCode *status); -int intl_charFromString(const UnicodeString &from, char **res, int *res_len, UErrorCode *status); +int intl_charFromString(const UnicodeString &from, char **res, size_t *res_len, UErrorCode *status); #endif /* INTL_CONVERTCPP_H */ diff --git a/ext/intl/intl_data.h b/ext/intl/intl_data.h index 6467d40909..26814a214c 100644 --- a/ext/intl/intl_data.h +++ b/ext/intl/intl_data.h @@ -81,7 +81,7 @@ typedef struct _intl_data { #define INTL_METHOD_RETVAL_UTF8(obj, ustring, ulen, free_it) \ { \ char *u8value; \ - int u8len; \ + size_t u8len; \ intl_convert_utf16_to_utf8(&u8value, &u8len, ustring, ulen, &INTL_DATA_ERROR_CODE((obj))); \ if((free_it)) { \ efree(ustring); \ @@ -96,14 +96,14 @@ typedef struct _intl_data { #define INTL_CHECK_LOCALE_LEN(locale_len) \ if((locale_len) > INTL_MAX_LOCALE_LEN) { \ intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, \ - "Locale string too long, should be no longer than 80 characters", 0 ); \ + "Locale string too long, should be no longer than 80 characters", 0 ); \ RETURN_NULL(); \ } #define INTL_CHECK_LOCALE_LEN_OBJ(locale_len, object) \ if((locale_len) > INTL_MAX_LOCALE_LEN) { \ intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, \ - "Locale string too long, should be no longer than 80 characters", 0 ); \ + "Locale string too long, should be no longer than 80 characters", 0 ); \ zval_dtor(object); \ ZVAL_NULL(object); \ RETURN_NULL(); \ diff --git a/ext/intl/intl_error.c b/ext/intl/intl_error.c index 046fd5302d..401e5b187b 100644 --- a/ext/intl/intl_error.c +++ b/ext/intl/intl_error.c @@ -248,7 +248,7 @@ smart_str intl_parse_error_to_string( UParseError* pe ) { smart_str ret = {0}; char *buf; - int u8len; + size_t u8len; UErrorCode status; int any = 0; diff --git a/ext/intl/locale/locale_methods.c b/ext/intl/locale/locale_methods.c index e8f51398e6..a03477ca29 100644 --- a/ext/intl/locale/locale_methods.c +++ b/ext/intl/locale/locale_methods.c @@ -476,7 +476,7 @@ static void get_icu_disp_value_src_php( char* tag_name, INTERNAL_FUNCTION_PARAME size_t loc_name_len = 0; const char* disp_loc_name = NULL; - size_t disp_loc_name_len = 0; + size_t disp_loc_name_len = 0; int free_loc_name = 0; UChar* disp_name = NULL; @@ -488,7 +488,7 @@ static void get_icu_disp_value_src_php( char* tag_name, INTERNAL_FUNCTION_PARAME UErrorCode status = U_ZERO_ERROR; char* utf8value = NULL; - int utf8value_len = 0; + size_t utf8value_len = 0; char* msg = NULL; int grOffset = 0; diff --git a/ext/intl/msgformat/msgformat.c b/ext/intl/msgformat/msgformat.c index a9999dc141..4bcc047e02 100644 --- a/ext/intl/msgformat/msgformat.c +++ b/ext/intl/msgformat/msgformat.c @@ -30,7 +30,7 @@ static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS) { const char* locale; char* pattern; - size_t locale_len = 0, pattern_len = 0; + size_t locale_len = 0, pattern_len = 0; UChar* spattern = NULL; int spattern_len = 0; zval* object; diff --git a/ext/intl/msgformat/msgformat_attr.c b/ext/intl/msgformat/msgformat_attr.c index ca117c539f..57cdbf6852 100644 --- a/ext/intl/msgformat/msgformat_attr.c +++ b/ext/intl/msgformat/msgformat_attr.c @@ -62,8 +62,8 @@ PHP_FUNCTION( msgfmt_get_pattern ) PHP_FUNCTION( msgfmt_set_pattern ) { char* value = NULL; - size_t value_len = 0; - int spattern_len = 0; + size_t value_len = 0; + int32_t spattern_len = 0; UChar* spattern = NULL; MSG_FORMAT_METHOD_INIT_VARS; diff --git a/ext/intl/msgformat/msgformat_format.c b/ext/intl/msgformat/msgformat_format.c index dda72249fc..5aa68e2735 100644 --- a/ext/intl/msgformat/msgformat_format.c +++ b/ext/intl/msgformat/msgformat_format.c @@ -36,7 +36,7 @@ static void msgfmt_do_format(MessageFormatter_object *mfo, zval *args, zval *ret { int count; UChar* formatted = NULL; - int formatted_len = 0; + int32_t formatted_len = 0; HashTable *args_copy; count = zend_hash_num_elements(Z_ARRVAL_P(args)); @@ -101,9 +101,9 @@ PHP_FUNCTION( msgfmt_format_message ) UChar *spattern = NULL; int spattern_len = 0; char *pattern = NULL; - size_t pattern_len = 0; + size_t pattern_len = 0; const char *slocale = NULL; - size_t slocale_len = 0; + size_t slocale_len = 0; MessageFormatter_object mf = {0}; MessageFormatter_object *mfo = &mf; diff --git a/ext/intl/msgformat/msgformat_helpers.cpp b/ext/intl/msgformat/msgformat_helpers.cpp index 93c4290601..76fdc3847b 100644 --- a/ext/intl/msgformat/msgformat_helpers.cpp +++ b/ext/intl/msgformat/msgformat_helpers.cpp @@ -363,7 +363,7 @@ static void umsg_set_timezone(MessageFormatter_object *mfo, U_CFUNC void umsg_format_helper(MessageFormatter_object *mfo, HashTable *args, UChar **formatted, - int *formatted_len) + int32_t *formatted_len) { int arg_count = zend_hash_num_elements(args); std::vector<Formattable> fargs; @@ -388,7 +388,7 @@ U_CFUNC void umsg_format_helper(MessageFormatter_object *mfo, // Key related variables zend_string *str_index; - zend_ulong num_index; + zend_ulong num_index; ZEND_HASH_FOREACH_KEY_VAL(args, num_index, str_index, elem) { Formattable& formattable = fargs[argNum]; @@ -537,10 +537,9 @@ retry_kint64: double dd = intl_zval_to_millis(elem, &err, "msgfmt_format"); if (U_FAILURE(err.code)) { char *message, *key_char; - int key_len; + size_t key_len; UErrorCode status = UErrorCode(); - if (intl_charFromString(key, &key_char, &key_len, - &status) == SUCCESS) { + if (intl_charFromString(key, &key_char, &key_len, &status) == SUCCESS) { spprintf(&message, 0, "The argument for key '%s' " "cannot be used as a date or time", key_char); intl_errors_set(&err, err.code, message, 1); @@ -581,7 +580,7 @@ retry_kint64: default: { char *message, *key_char; - int key_len; + size_t key_len; UErrorCode status = UErrorCode(); if (intl_charFromString(key, &key_char, &key_len, &status) == SUCCESS) { @@ -628,7 +627,7 @@ retry_kint64: #define cleanup_zvals() for(int j=i;j>=0;j--) { zval_ptr_dtor((*args)+i); } -U_CFUNC void umsg_parse_helper(UMessageFormat *fmt, int *count, zval **args, UChar *source, int source_len, UErrorCode *status) +U_CFUNC void umsg_parse_helper(UMessageFormat *fmt, int *count, zval **args, UChar *source, int32_t source_len, UErrorCode *status) { UnicodeString srcString(source, source_len); Formattable *fargs = ((const MessageFormat*)fmt)->parse(srcString, *count, *status); @@ -645,7 +644,7 @@ U_CFUNC void umsg_parse_helper(UMessageFormat *fmt, int *count, zval **args, UCh double aDate; UnicodeString temp; char *stmp; - int stmp_len; + size_t stmp_len; switch(fargs[i].getType()) { case Formattable::kDate: diff --git a/ext/intl/msgformat/msgformat_parse.c b/ext/intl/msgformat/msgformat_parse.c index 1474ff6ea8..6bcdba129c 100644 --- a/ext/intl/msgformat/msgformat_parse.c +++ b/ext/intl/msgformat/msgformat_parse.c @@ -92,11 +92,11 @@ PHP_FUNCTION( msgfmt_parse_message ) UChar *spattern = NULL; int spattern_len = 0; char *pattern = NULL; - size_t pattern_len = 0; + size_t pattern_len = 0; const char *slocale = NULL; - size_t slocale_len = 0; + size_t slocale_len = 0; char *source = NULL; - size_t src_len = 0; + size_t src_len = 0; MessageFormatter_object mf = {0}; MessageFormatter_object *mfo = &mf; diff --git a/ext/intl/normalizer/normalizer_normalize.c b/ext/intl/normalizer/normalizer_normalize.c index 97163a98c4..5b0c980d76 100644 --- a/ext/intl/normalizer/normalizer_normalize.c +++ b/ext/intl/normalizer/normalizer_normalize.c @@ -34,19 +34,19 @@ PHP_FUNCTION( normalizer_normalize ) { char* input = NULL; /* form is optional, defaults to FORM_C */ - zend_long form = NORMALIZER_DEFAULT; + zend_long form = NORMALIZER_DEFAULT; size_t input_len = 0; UChar* uinput = NULL; - int uinput_len = 0; - int expansion_factor = 1; + int32_t uinput_len = 0; + int expansion_factor = 1; UErrorCode status = U_ZERO_ERROR; UChar* uret_buf = NULL; - int uret_len = 0; + int32_t uret_len = 0; char* ret_buf = NULL; - int32_t ret_len = 0; + size_t ret_len = 0; int32_t size_needed; diff --git a/ext/intl/resourcebundle/resourcebundle.c b/ext/intl/resourcebundle/resourcebundle.c index 62a268c07f..1a6ff1f88c 100644 --- a/ext/intl/resourcebundle/resourcebundle.c +++ b/ext/intl/resourcebundle/resourcebundle.c @@ -32,7 +32,7 @@ void resourcebundle_extract_value( zval *return_value, ResourceBundle_object *so const int32_t* vfield; int32_t ilen; int i; - zend_long lfield; + zend_long lfield; ResourceBundle_object* newrb; restype = ures_getType( source->child ); diff --git a/ext/intl/resourcebundle/resourcebundle_class.c b/ext/intl/resourcebundle/resourcebundle_class.c index 67e2bae855..d56544c5ae 100644 --- a/ext/intl/resourcebundle/resourcebundle_class.c +++ b/ext/intl/resourcebundle/resourcebundle_class.c @@ -76,10 +76,10 @@ static zend_object *ResourceBundle_object_create( zend_class_entry *ce ) /* {{{ ResourceBundle_ctor */ static void resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS) { - const char *bundlename; - size_t bundlename_len = 0; - const char *locale; - size_t locale_len = 0; + const char *bundlename; + size_t bundlename_len = 0; + const char *locale; + size_t locale_len = 0; zend_bool fallback = 1; zval *object = return_value; @@ -179,7 +179,7 @@ static void resourcebundle_array_fetch(zval *object, zval *offset, zval *return_ if(Z_TYPE_P(offset) == IS_LONG) { is_numeric = 1; - meindex = Z_LVAL_P(offset); + meindex = (int32_t)Z_LVAL_P(offset); rb->child = ures_getByIndex( rb->me, meindex, rb->child, &INTL_DATA_ERROR_CODE(rb) ); } else if(Z_TYPE_P(offset) == IS_STRING) { mekey = Z_STRVAL_P(offset); diff --git a/ext/intl/resourcebundle/resourcebundle_iterator.h b/ext/intl/resourcebundle/resourcebundle_iterator.h index f27b76ad8b..01213ac76e 100644 --- a/ext/intl/resourcebundle/resourcebundle_iterator.h +++ b/ext/intl/resourcebundle/resourcebundle_iterator.h @@ -25,10 +25,10 @@ typedef struct { zend_object_iterator intern; ResourceBundle_object *subject; zend_bool is_table; - zend_long length; + zend_long length; zval current; char *currentkey; - zend_long i; + zend_long i; } ResourceBundle_iterator; zend_object_iterator *resourcebundle_get_iterator( zend_class_entry *ce, zval *object, int byref ); diff --git a/ext/intl/spoofchecker/spoofchecker_main.c b/ext/intl/spoofchecker/spoofchecker_main.c index fb0f1549a2..8a94fd0421 100644 --- a/ext/intl/spoofchecker/spoofchecker_main.c +++ b/ext/intl/spoofchecker/spoofchecker_main.c @@ -70,9 +70,11 @@ PHP_METHOD(Spoofchecker, areConfusable) } SPOOFCHECKER_METHOD_FETCH_OBJECT; - - ret = uspoof_areConfusableUTF8(co->uspoof, s1, s1_len, s2, s2_len, SPOOFCHECKER_ERROR_CODE_P(co)); - + if(s1_len > INT32_MAX || s2_len > INT32_MAX) { + SPOOFCHECKER_ERROR_CODE(co) = U_BUFFER_OVERFLOW_ERROR; + } else { + ret = uspoof_areConfusableUTF8(co->uspoof, s1, (int32_t)s1_len, s2, (int32_t)s2_len, SPOOFCHECKER_ERROR_CODE_P(co)); + } if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) { php_error_docref(NULL, E_WARNING, "(%d) %s", SPOOFCHECKER_ERROR_CODE(co), u_errorName(SPOOFCHECKER_ERROR_CODE(co))); RETURN_TRUE; diff --git a/ext/intl/timezone/timezone_class.cpp b/ext/intl/timezone/timezone_class.cpp index 6818d0d9d8..99b95e14a8 100644 --- a/ext/intl/timezone/timezone_class.cpp +++ b/ext/intl/timezone/timezone_class.cpp @@ -87,7 +87,7 @@ U_CFUNC zval *timezone_convert_to_datetimezone(const TimeZone *timeZone, tzobj->tzi.utc_offset = -1 * timeZone->getRawOffset() / (60 * 1000); } else { char *str; - int str_len; + size_t str_len; /* Call the constructor! */ if (intl_charFromString(id, &str, &str_len, &INTL_ERROR_CODE(*outside_error)) == FAILURE) { spprintf(&message, 0, "%s: could not convert id to UTF-8", func); @@ -292,7 +292,7 @@ static HashTable *TimeZone_get_debug_info(zval *object, int *is_temp) const TimeZone *tz; UnicodeString ustr; char *str; - int str_len; + size_t str_len; HashTable *debug_info; UErrorCode uec = U_ZERO_ERROR; diff --git a/ext/intl/timezone/timezone_methods.cpp b/ext/intl/timezone/timezone_methods.cpp index 8a3c2cc7a8..053918ad04 100644 --- a/ext/intl/timezone/timezone_methods.cpp +++ b/ext/intl/timezone/timezone_methods.cpp @@ -47,11 +47,10 @@ U_CFUNC PHP_METHOD(IntlTimeZone, __construct) U_CFUNC PHP_FUNCTION(intltz_create_time_zone) { char *str_id; - size_t str_id_len; + size_t str_id_len; intl_error_reset(NULL); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", - &str_id, &str_id_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &str_id, &str_id_len) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intltz_create_time_zone: bad arguments", 0); RETURN_NULL(); @@ -209,7 +208,7 @@ double_offset: U_CFUNC PHP_FUNCTION(intltz_count_equivalent_ids) { char *str_id; - size_t str_id_len; + size_t str_id_len; intl_error_reset(NULL); if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", @@ -234,12 +233,12 @@ U_CFUNC PHP_FUNCTION(intltz_count_equivalent_ids) #if U_ICU_VERSION_MAJOR_NUM * 10 + U_ICU_VERSION_MINOR_NUM >= 48 U_CFUNC PHP_FUNCTION(intltz_create_time_zone_id_enumeration) { - zend_long zoneType, - offset_arg; - char *region = NULL; - size_t region_len = 0; - int32_t offset, - *offsetp = NULL; + zend_long zoneType, + offset_arg; + char *region = NULL; + size_t region_len = 0; + int32_t offset, + *offsetp = NULL; zend_bool arg3isnull = 1; intl_error_reset(NULL); @@ -282,7 +281,7 @@ U_CFUNC PHP_FUNCTION(intltz_create_time_zone_id_enumeration) U_CFUNC PHP_FUNCTION(intltz_get_canonical_id) { char *str_id; - size_t str_id_len; + size_t str_id_len; zval *is_systemid = NULL; intl_error_reset(NULL); @@ -307,7 +306,7 @@ U_CFUNC PHP_FUNCTION(intltz_get_canonical_id) INTL_CHECK_STATUS(status, "intltz_get_canonical_id: error obtaining canonical ID"); char *str; - int str_len; + size_t str_len; intl_convert_utf16_to_utf8(&str, &str_len, result.getBuffer(), result.length(), &status); INTL_CHECK_STATUS(status, "intltz_get_canonical_id: could not convert time zone id to UTF-16"); @@ -326,8 +325,8 @@ U_CFUNC PHP_FUNCTION(intltz_get_canonical_id) U_CFUNC PHP_FUNCTION(intltz_get_region) { char *str_id; - size_t str_id_len; - char outbuf[3]; + size_t str_id_len; + char outbuf[3]; intl_error_reset(NULL); if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", @@ -372,7 +371,7 @@ U_CFUNC PHP_FUNCTION(intltz_get_tz_data_version) U_CFUNC PHP_FUNCTION(intltz_get_equivalent_id) { - char *str_id; + char *str_id; size_t str_id_len; zend_long index; intl_error_reset(NULL); @@ -395,7 +394,7 @@ U_CFUNC PHP_FUNCTION(intltz_get_equivalent_id) const UnicodeString result = TimeZone::getEquivalentID(id, (int32_t)index); char *str; - int str_len; + size_t str_len; intl_convert_utf16_to_utf8(&str, &str_len, result.getBuffer(), result.length(), &status); INTL_CHECK_STATUS(status, "intltz_get_equivalent_id: " @@ -421,8 +420,8 @@ U_CFUNC PHP_FUNCTION(intltz_get_id) UnicodeString id_us; to->utimezone->getID(id_us); - char *id = NULL; - int id_len = 0; + char *id = NULL; + size_t id_len = 0; intl_convert_utf16_to_utf8(&id, &id_len, id_us.getBuffer(), id_us.length(), TIMEZONE_ERROR_CODE_P(to)); @@ -536,9 +535,9 @@ static const TimeZone::EDisplayType display_types[] = { U_CFUNC PHP_FUNCTION(intltz_get_display_name) { zend_bool daylight = 0; - zend_long display_type = TimeZone::LONG; - const char *locale_str = NULL; - size_t dummy = 0; + zend_long display_type = TimeZone::LONG; + const char *locale_str = NULL; + size_t dummy = 0; TIMEZONE_METHOD_INIT_VARS; if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), @@ -571,7 +570,7 @@ U_CFUNC PHP_FUNCTION(intltz_get_display_name) Locale::createFromName(locale_str), result); char *str; - int str_len; + size_t str_len; intl_convert_utf16_to_utf8(&str, &str_len, result.getBuffer(), result.length(), TIMEZONE_ERROR_CODE_P(to)); INTL_METHOD_CHECK_STATUS(to, "intltz_get_display_name: " "could not convert resulting time zone id to UTF-16"); diff --git a/ext/intl/transliterator/transliterator_class.c b/ext/intl/transliterator/transliterator_class.c index 4b799d1802..c40c5e33ce 100644 --- a/ext/intl/transliterator/transliterator_class.c +++ b/ext/intl/transliterator/transliterator_class.c @@ -37,7 +37,7 @@ int transliterator_object_construct( zval *object, const UChar *ustr_id; int32_t ustr_id_len; char *str_id; - int str_id_len; + size_t str_id_len; Transliterator_object *to; TRANSLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK; diff --git a/ext/intl/transliterator/transliterator_methods.c b/ext/intl/transliterator/transliterator_methods.c index 66db8bf522..22c608c9d4 100644 --- a/ext/intl/transliterator/transliterator_methods.c +++ b/ext/intl/transliterator/transliterator_methods.c @@ -27,7 +27,7 @@ #include <zend_exceptions.h> -static int create_transliterator( char *str_id, int str_id_len, zend_long direction, zval *object ) +static int create_transliterator( char *str_id, size_t str_id_len, zend_long direction, zval *object ) { Transliterator_object *to; UChar *ustr_id = NULL; @@ -103,9 +103,9 @@ static int create_transliterator( char *str_id, int str_id_len, zend_long direct */ PHP_FUNCTION( transliterator_create ) { - char *str_id; - size_t str_id_len; - zend_long direction = TRANSLITERATOR_FORWARD; + char *str_id; + size_t str_id_len; + zend_long direction = TRANSLITERATOR_FORWARD; int res; TRANSLITERATOR_METHOD_INIT_VARS; @@ -136,10 +136,10 @@ PHP_FUNCTION( transliterator_create ) PHP_FUNCTION( transliterator_create_from_rules ) { char *str_rules; - size_t str_rules_len; + size_t str_rules_len; UChar *ustr_rules = NULL; int32_t ustr_rules_len = 0; - zend_long direction = TRANSLITERATOR_FORWARD; + zend_long direction = TRANSLITERATOR_FORWARD; UParseError parse_error = {0, -1}; UTransliterator *utrans; UChar id[] = {0x52, 0x75, 0x6C, 0x65, 0x73, 0x54, 0x72, @@ -266,7 +266,7 @@ PHP_FUNCTION( transliterator_list_ids ) while( (elem = uenum_unext( en, &elem_len, &status )) ) { char *el_char = NULL; - int el_len = 0; + size_t el_len = 0; intl_convert_utf16_to_utf8( &el_char, &el_len, elem, elem_len, &status ); @@ -303,11 +303,11 @@ PHP_FUNCTION( transliterator_transliterate ) char *str; UChar *ustr = NULL, *uresult = NULL; - size_t str_len; + size_t str_len; int32_t ustr_len = 0, capacity, uresult_len; - zend_long start = 0, + zend_long start = 0, limit = -1; int success = 0; zval tmp_object; |