com php-src: Merge branch 'PHP-7.2': ext/mbstring/mbstring.c

From: Date: Thu, 03 Aug 2017 20:41:15 +0000
Subject: com php-src: Merge branch 'PHP-7.2': ext/mbstring/mbstring.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-98940@lists.php.net to get a copy of this message
Commit: 5caf05f6c53f0d2eb87e248944d1000a3277e12f Author: Nikita Popov <nikita.ppv@gmail.com> Thu, 3 Aug 2017 22:41:15 +0200 Parents: c98714f19e6f033a7b45a24cf73fc9460cee3254 e53162a32b011ef22c3e0210e7af334d968f227c Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=5caf05f6c53f0d2eb87e248944d1000a3277e12f Log: Merge branch 'PHP-7.2' Changed paths: MM ext/mbstring/mbstring.c Diff: diff --cc ext/mbstring/mbstring.c index a5430b4,5618d7a..57f298e --- a/ext/mbstring/mbstring.c +++ b/ext/mbstring/mbstring.c @@@ -4888,43 -5051,30 +4879,27 @@@ PHP_FUNCTION(mb_check_encoding /* }}} */ -static inline zend_long php_mb_ord(const char* str, size_t str_len, const char* enc) +static inline zend_long php_mb_ord(const char* str, size_t str_len, const char* enc_name) { + const mbfl_encoding *enc; enum mbfl_no_encoding no_enc; char* ret; - size_t ret_len, char_len; + size_t ret_len; zend_long cp; - if (enc == NULL) { - no_enc = MBSTRG(current_internal_encoding)->no_encoding; - } else { - no_enc = mbfl_name2no_encoding(enc); - - if (no_enc == mbfl_no_encoding_invalid) { - php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", enc); - return -1; - } + enc = php_mb_get_encoding(enc_name); + if (!enc) { + return -1; } + no_enc = enc->no_encoding; - if (php_mb_is_no_encoding_unicode(no_enc)) { - ret = php_mb_convert_encoding_ex(str, str_len, &mbfl_encoding_ucs4be, enc, &ret_len); - - if (ret == NULL) { - return -1; - } - - cp = (unsigned char) ret[0] << 24 | \ - (unsigned char) ret[1] << 16 | \ - (unsigned char) ret[2] << 8 | \ - (unsigned char) ret[3]; - - efree(ret); - - return cp; - - } else if (php_mb_is_unsupported_no_encoding(no_enc)) { + if (php_mb_is_unsupported_no_encoding(no_enc)) { - php_error_docref(NULL, E_WARNING, "Unsupported encoding \"%s\"", enc); + php_error_docref(NULL, E_WARNING, "Unsupported encoding \"%s\"", enc_name); return -1; } - ret = php_mb_convert_encoding_ex(str, str_len, enc, enc, &ret_len); - ret = php_mb_convert_encoding(str, str_len, "UCS-4BE", enc, &ret_len); ++ ret = php_mb_convert_encoding_ex(str, str_len, &mbfl_encoding_ucs4be, enc, &ret_len); + if (ret == NULL) { return -1; } @@@ -4988,17 -5124,28 +4950,24 @@@ static inline char* php_mb_chr(zend_lon char* ret; size_t ret_len; - if (enc == NULL) { - no_enc = MBSTRG(current_internal_encoding)->no_encoding; - } else { - no_enc = mbfl_name2no_encoding(enc); - if (no_enc == mbfl_no_encoding_invalid) { - php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", enc); - return NULL; - } + enc = php_mb_get_encoding(enc_name); + if (!enc) { + return NULL; } + no_enc = enc->no_encoding; + if (php_mb_is_unsupported_no_encoding(no_enc)) { - php_error_docref(NULL, E_WARNING, "Unsupported encoding \"%s\"", enc); ++ php_error_docref(NULL, E_WARNING, "Unsupported encoding \"%s\"", enc_name); + return NULL; + } - if (php_mb_is_no_encoding_utf8(no_enc)) { + if (cp < 0 || cp > 0x10ffff) { + return NULL; + } - if (0 > cp || cp > 0x10ffff || (cp > 0xd7ff && 0xe000 > cp)) { - cp = MBSTRG(current_filter_illegal_substchar); + if (php_mb_is_no_encoding_utf8(no_enc)) { + if (cp > 0xd7ff && 0xe000 > cp) { + return NULL; } if (cp < 0x80) { @@@ -5034,80 -5181,31 +5003,31 @@@ } return ret; + } - } else if (php_mb_is_no_encoding_unicode(no_enc)) { - - if (0 > cp || 0x10ffff < cp) { - - if (php_mb_is_no_encoding_unicode(MBSTRG(current_internal_encoding)->no_encoding)) { - cp = MBSTRG(current_filter_illegal_substchar); - } else { - cp = 0x3f; - } - - } - - buf_len = 4; - buf = (char *) safe_emalloc(buf_len, 1, 1); - buf[0] = (cp >> 24) & 0xff; - buf[1] = (cp >> 16) & 0xff; - buf[2] = (cp >> 8) & 0xff; - buf[3] = cp & 0xff; - buf[4] = 0; + buf_len = 4; + buf = (char *) safe_emalloc(buf_len, 1, 1); + buf[0] = (cp >> 24) & 0xff; + buf[1] = (cp >> 16) & 0xff; + buf[2] = (cp >> 8) & 0xff; + buf[3] = cp & 0xff; + buf[4] = 0; + { + long orig_illegalchars = MBSTRG(illegalchars); + MBSTRG(illegalchars) = 0; - ret = php_mb_convert_encoding(buf, buf_len, enc, "UCS-4BE", &ret_len); + ret = php_mb_convert_encoding_ex(buf, buf_len, enc, &mbfl_encoding_ucs4be, &ret_len); - efree(buf); - - if (output_len) { - *output_len = ret_len; - } - - return ret; - - } else if (php_mb_is_unsupported_no_encoding(no_enc)) { - php_error_docref(NULL, E_WARNING, "Unsupported encoding \"%s\"", enc_name); - return NULL; - } - - if (0 > cp || cp > 0x100000000) { - if (no_enc == MBSTRG(current_internal_encoding)->no_encoding) { - cp = MBSTRG(current_filter_illegal_substchar); - } else { - cp = 0x3f; + if (MBSTRG(illegalchars) != 0) { + efree(buf); + efree(ret); + MBSTRG(illegalchars) = orig_illegalchars; + return NULL; } - } - if (cp < 0x100) { - buf_len = 1; - buf = (char *) safe_emalloc(buf_len, 1, 1); - buf[0] = cp; - buf[1] = 0; - } else if (cp < 0x10000) { - buf_len = 2; - buf = (char *) safe_emalloc(buf_len, 1, 1); - buf[0] = cp >> 8; - buf[1] = cp & 0xff; - buf[2] = 0; - } else if (cp < 0x1000000) { - buf_len = 3; - buf = (char *) safe_emalloc(buf_len, 1, 1); - buf[0] = cp >> 16; - buf[1] = (cp >> 8) & 0xff; - buf[2] = cp & 0xff; - buf[3] = 0; - } else { - buf_len = 4; - buf = (char *) safe_emalloc(buf_len, 1, 1); - buf[0] = cp >> 24; - buf[1] = (cp >> 16) & 0xff; - buf[2] = (cp >> 8) & 0xff; - buf[3] = cp & 0xff; - buf[4] = 0; + MBSTRG(illegalchars) = orig_illegalchars; } - ret = php_mb_convert_encoding_ex(buf, buf_len, enc, enc, &ret_len); efree(buf); - if (output_len) { *output_len = ret_len; }

« previous php.cvs (#98940) next »