]> granicus.if.org Git - php/commitdiff
cleanup intl types
authorStanislav Malyshev <stas@php.net>
Mon, 29 Dec 2014 10:17:15 +0000 (02:17 -0800)
committerStanislav Malyshev <stas@php.net>
Mon, 29 Dec 2014 22:06:12 +0000 (14:06 -0800)
44 files changed:
ext/intl/breakiterator/breakiterator_iterators.cpp
ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp
ext/intl/collator/collator_convert.c
ext/intl/collator/collator_create.c
ext/intl/collator/collator_is_numeric.c
ext/intl/collator/collator_is_numeric.h
ext/intl/collator/collator_sort.c
ext/intl/common/common_date.cpp
ext/intl/converter/converter.c
ext/intl/dateformat/dateformat_attr.c
ext/intl/dateformat/dateformat_attrcpp.cpp
ext/intl/dateformat/dateformat_create.cpp
ext/intl/dateformat/dateformat_data.h
ext/intl/dateformat/dateformat_format_object.cpp
ext/intl/dateformat/dateformat_parse.c
ext/intl/formatter/formatter_attr.c
ext/intl/formatter/formatter_format.c
ext/intl/formatter/formatter_main.c
ext/intl/formatter/formatter_parse.c
ext/intl/grapheme/grapheme_string.c
ext/intl/grapheme/grapheme_util.c
ext/intl/grapheme/grapheme_util.h
ext/intl/idn/idn.c
ext/intl/intl_convert.c
ext/intl/intl_convert.h
ext/intl/intl_convertcpp.cpp
ext/intl/intl_convertcpp.h
ext/intl/intl_data.h
ext/intl/intl_error.c
ext/intl/locale/locale_methods.c
ext/intl/msgformat/msgformat.c
ext/intl/msgformat/msgformat_attr.c
ext/intl/msgformat/msgformat_format.c
ext/intl/msgformat/msgformat_helpers.cpp
ext/intl/msgformat/msgformat_parse.c
ext/intl/normalizer/normalizer_normalize.c
ext/intl/resourcebundle/resourcebundle.c
ext/intl/resourcebundle/resourcebundle_class.c
ext/intl/resourcebundle/resourcebundle_iterator.h
ext/intl/spoofchecker/spoofchecker_main.c
ext/intl/timezone/timezone_class.cpp
ext/intl/timezone/timezone_methods.cpp
ext/intl/transliterator/transliterator_class.c
ext/intl/transliterator/transliterator_methods.c

index 624a813e5487cd8ad4abb35c2fcbd8f30b459fc9..2ff698b87e34423b704948a19f5f0a3985b99874 100644 (file)
@@ -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);
index be38396466f64b165e85a9f01d1ab15aeeda0f6e..e359bacf413427c8f4fe3961cca9cdb8c758c0c2 100644 (file)
@@ -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)
index 8ff63a902e0af5006b1ecf656f96699db7a10ff3..23fd00001da9a0125a53a912cf8e9b2cd4b45908 100644 (file)
@@ -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 )
index 3945fb78b3fb3a199d2a13a20400a83076b97c24..2d98ea9d01f6d8d3bd909725293b84b7596c9fc2 100644 (file)
@@ -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;
 
index a93cd962f3268928ac907ac3dac067697b2b009b..6b0568dd6440fc895153471ef9b110582cb937f9 100644 (file)
@@ -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;
index 5ede4fa922f8865df45cf3f63a25b11df859992f..f6337aaaccbe71f0ce0f9d24fd4a6ec131fbeb19 100644 (file)
@@ -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
index d0d6b1a9d9de95d7c4f8a604c9d4934b714e4d46..8914736deec619d8b56481ebfa290164fda9a607 100644 (file)
@@ -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;
 
index 326e8c01c9d18628a49ce0627f3cf4340f20a90b..f1bf75ab0fa67455cf8a17281c26c73d45543b02 100644 (file)
@@ -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;
 
index f52d0490cce7e954ad9b78d9aad72e1991a60022..c9ad9a9409f0fc64051ed8be3325e1f76cba674d 100644 (file)
@@ -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);
index ee8b91dbed0681fac8269ffc8728c2bacc4c5294..60ef45b7b3fab4c23cff59b99551c792c29f9e43 100644 (file)
@@ -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;
 
index 52df471a10d194f15759388c2e49db0dcbc99e06..1b9716eceb45863ca5ff42480e5138190384c1e4 100644 (file)
@@ -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",
index 9a90029ca159e1330c3d47ce67df26b0e2ac9e7f..2ceee460ce7c3e5f1ab197a5eb30edf10b04a311 100644 (file)
@@ -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);
index aaf61e626628f9c86370c6fca4dffaa41b3893d7..ed61c75594a08a03fa7d4a0373dc73b7e97484f5 100644 (file)
@@ -23,7 +23,7 @@
 #include "intl_error.h"
 
 typedef struct {
-       // error hangling
+       // error handling
        intl_error      error;
 
        // formatter handling
index fe38a7128794afbac3262778c0cacfd611bfbbad..1df6cc9612ea4ff436350bece06f570ded5d31a3 100644 (file)
@@ -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);
 
index 7d12f877e7341839e6f56be4275fe78bd03d6329..15d19485ed8593ff2dc9eac017c11d1a539b6e6e 100644 (file)
@@ -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;
index d3189df6d6de9b929216d74f097ce2924627a1b4..f5a4cafe3cc2a896b1a82c2f61b051ed4cf1a68d 100644 (file)
@@ -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;
 
index b852e54b3e6c42494618c10a7582d008bf2c7b20..a46efd9660900a70d785ce69be22d7ea39e09f88 100644 (file)
@@ -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. */
index 067f3bd82b054f21d7dab0b24ce6dd0c2a7a7a33..59629a68f938861569613ca40a3ca53b1e6c7709 100644 (file)
@@ -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. */
index b2af74a2e05c3687d3d0699cb66924589165f80a..43f6780e57ed3432faac3721779cb6bf37950c07 100644 (file)
@@ -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;
index d5a33fe663459d8de5665da4f13ebfb0c7647825..91cc1802ae9d9c27bdae16972cf4fcf5e6e574a6 100644 (file)
@@ -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);
index bb4ecac0848ef5b4c29afabe368b2ff3c24141ba..c3db4aabdf9bf45e37ef7ffd479f74003b1dc8c7 100644 (file)
@@ -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;
index 99021287fa9fe0de05dae0be84e7f0fce53e80ce..492b19bb7fed9952dbc1662e0662fbcbf6b2e64b 100644 (file)
 /* 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 );
 
index 0848be94a702cf5de016af93954773dded68a3bd..1bd9f6d2a39f958355d1a7c4a9bb157d1fc9be3e 100644 (file)
@@ -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
index 50a742082fc3fe284edcf3eca108e324cb01a7aa..51537062f5068906f6f0d4b1000a7037e61141d0 100644 (file)
  * 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;
 }
 /* }}} */
 
index 952d765c527a46ea98fdb9570c401fe477d7d7fc..2885890ef324a1ad02651b6c2408b555d0315d95 100644 (file)
 #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
index f52348bc25f22c106c75993c46a0cb81de41c51a..35077376165d1d17c0dadb851bd16e827d8db634 100644 (file)
@@ -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;
 }
index fc2242a6b8b2000075e56a09823f13272676ebd0..c4b689166d9c44bcf1722b6e2a0c0b5a854803d0 100644 (file)
@@ -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 */
index 6467d40909ad442aa763553baefdce90ee6e7462..26814a214c072c879f562ef1c7d779d2fc94c7f7 100644 (file)
@@ -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();                                                                                                                                  \
index 046fd5302d755de06b5b85503730ea3ce7f4747d..401e5b187b6213176426ad7297fd7d2923e4de35 100644 (file)
@@ -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;
 
index e8f51398e65082123816877b9cc38d5026a78127..a03477ca29597ad8821b02d41e47906660f3c7da 100644 (file)
@@ -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;
index a9999dc141519f4a77c5814af19a3c3eb30b5819..4bcc047e02fddf7f94c4a301d2173e68b440e39f 100644 (file)
@@ -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;
index ca117c539f8606328bc23a2bd60b1b272482e7aa..57cdbf6852491c14f936e43f2f468919121df531 100644 (file)
@@ -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;
 
index dda72249fcf928a60771262c37456099ef5c3c19..5aa68e27354d85f49e037b0e6a842e692d52d265 100644 (file)
@@ -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;
 
index 93c42906012d3afc05f6dfb1fb3d3f7969351b1b..76fdc3847bcf512109689e4a7683543c7aab7c78 100644 (file)
@@ -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:
index 1474ff6ea838d21b3cf0bcd3f084468fe54fc47a..6bcdba129c179ffc302121cac9b0c033a1f9c74d 100644 (file)
@@ -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;
 
index 97163a98c4786f2aa6b4cb0442133e94f78df45a..5b0c980d7658e4dbd5bd75a3518115feb6c30b63 100644 (file)
@@ -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;
                
index 62a268c07f00e2c6e8c460e1f566152502e12786..1a6ff1f88c7ca55f42e7b0b6b80c4beb67b0587d 100644 (file)
@@ -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 );
index 67e2bae8554431a3b8243ac57cc23ae279188316..d56544c5aed0011534b3b8fa8025045535d5fefe 100644 (file)
@@ -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);
index f27b76ad8beb99ebdd4bd4e138a6d8553a924727..01213ac76eb9b34a21877bba8289b5c9f51efe2f 100644 (file)
@@ -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 );
index fb0f1549a2f0b0abeb07596537a844207b4ab98e..8a94fd04219dde0f1fce154e0f4e2667d510567a 100644 (file)
@@ -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;
index 6818d0d9d81416e26cf2617ff7cf7039ca368b21..99b95e14a84dc53d32a07dd133f5a149be548227 100644 (file)
@@ -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;
 
index 8a3c2cc7a8de0b55865af6901df3aa9ea08dac54..053918ad049e379dfcb8c438b506c91e543fefbe 100644 (file)
@@ -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");
index 4b799d18029c82c534515e4b3f44ce9769a00fa9..c40c5e33ceabcd2527c2a424a01bc0bd20089181 100644 (file)
@@ -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;
index 66db8bf52278b42308ca7bdf793a48360dca5485..22c608c9d434e1dbbe485b319b3aee5e1a70f113 100644 (file)
@@ -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;