From: Xinchen Hui Date: Mon, 24 Mar 2014 05:56:27 +0000 (+0800) Subject: Fixed encoding list building while array arg X-Git-Tag: POST_PHPNG_MERGE~412^2~230 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=807ed2eb198eacb9b0d49b3557242fb12e1b0a15;p=php Fixed encoding list building while array arg --- diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c index 533e064a67..33f26dcaec 100644 --- a/ext/mbstring/mbstring.c +++ b/ext/mbstring/mbstring.c @@ -3073,44 +3073,44 @@ PHP_FUNCTION(mb_convert_encoding) if (ZEND_NUM_ARGS() == 3) { switch (Z_TYPE_P(arg_old)) { - case IS_ARRAY: - target_hash = Z_ARRVAL_P(arg_old); - zend_hash_internal_pointer_reset(target_hash); - i = zend_hash_num_elements(target_hash); - _from_encodings = NULL; + case IS_ARRAY: + target_hash = Z_ARRVAL_P(arg_old); + zend_hash_internal_pointer_reset(target_hash); + i = zend_hash_num_elements(target_hash); + _from_encodings = NULL; - while (i > 0) { - if ((hash_entry = zend_hash_get_current_data(target_hash)) == NULL) { - break; - } + while (i > 0) { + if ((hash_entry = zend_hash_get_current_data(target_hash)) == NULL) { + break; + } - convert_to_string_ex(hash_entry); + convert_to_string_ex(hash_entry); - if ( _from_encodings) { - l = strlen(_from_encodings); - n = strlen(Z_STRVAL_P(hash_entry)); - _from_encodings = erealloc(_from_encodings, l+n+2); - memcpy(_from_encodings + l, ",", 1); - memcpy(_from_encodings + l + 1, Z_STRVAL_P(hash_entry), Z_STRLEN_P(hash_entry)); - } else { - _from_encodings = estrdup(Z_STRVAL_P(hash_entry)); - } + if ( _from_encodings) { + l = strlen(_from_encodings); + n = strlen(Z_STRVAL_P(hash_entry)); + _from_encodings = erealloc(_from_encodings, l+n+2); + memcpy(_from_encodings + l, ",", 1); + memcpy(_from_encodings + l + 1, Z_STRVAL_P(hash_entry), Z_STRLEN_P(hash_entry) + 1); + } else { + _from_encodings = estrdup(Z_STRVAL_P(hash_entry)); + } - zend_hash_move_forward(target_hash); - i--; - } + zend_hash_move_forward(target_hash); + i--; + } - if (_from_encodings != NULL && !strlen(_from_encodings)) { - efree(_from_encodings); - _from_encodings = NULL; + if (_from_encodings != NULL && !strlen(_from_encodings)) { + efree(_from_encodings); + _from_encodings = NULL; + } + s_free = _from_encodings; + break; + default: + convert_to_string(arg_old); + _from_encodings = Z_STRVAL_P(arg_old); + break; } - s_free = _from_encodings; - break; - default: - convert_to_string(arg_old); - _from_encodings = Z_STRVAL_P(arg_old); - break; - } } /* new encoding */