From: Stanislav Malyshev Date: Sun, 27 Nov 2016 23:36:29 +0000 (-0800) Subject: Merge branch 'PHP-5.6' into PHP-7.0 X-Git-Tag: php-7.1.1RC1~178^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f1a9851c3e4aa5606d209b44742dc7156b49f7b7;p=php Merge branch 'PHP-5.6' into PHP-7.0 * PHP-5.6: Fix #68447: grapheme_extract take an extra trailing character --- f1a9851c3e4aa5606d209b44742dc7156b49f7b7 diff --cc ext/intl/grapheme/grapheme_string.c index 5687e3e260,d298bab98b..f69500429d --- a/ext/intl/grapheme/grapheme_string.c +++ b/ext/intl/grapheme/grapheme_string.c @@@ -868,44 -885,35 +855,35 @@@ PHP_FUNCTION(grapheme_extract if ( NULL != next ) { ZVAL_LONG(next, start+nsize); } - RETURN_STRINGL(((char *)pstr), nsize, 1); + 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, pstr, str_len, &status ); + utext_openUTF8(&ut, pstr, str_len, &status); if ( U_FAILURE( status ) ) { /* Set global error code. */ - intl_error_set_code( NULL, status TSRMLS_CC ); + intl_error_set_code( NULL, status ); /* Set error messages. */ - intl_error_set_custom_msg( NULL, "Error converting input string to UTF-16", 0 ); - - if ( NULL != ustr ) - efree( ustr ); - intl_error_set_custom_msg( NULL, "Error opening UTF-8 text", 0 TSRMLS_CC ); ++ intl_error_set_custom_msg( NULL, "Error opening UTF-8 text", 0 ); RETURN_FALSE; } bi = NULL; status = U_ZERO_ERROR; - bi = grapheme_get_break_iterator(u_break_iterator_buffer, &status TSRMLS_CC ); + bi = grapheme_get_break_iterator(u_break_iterator_buffer, &status ); - ubrk_setText(bi, ustr, ustr_len, &status); - + ubrk_setUText(bi, &ut, &status); /* if the caller put us in the middle of a grapheme, we can't detect it in all cases since we 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); - } + utext_close(&ut); ubrk_close(bi); if ( NULL != next ) {