From: Dmitry Stogov Date: Fri, 11 Jan 2008 15:10:50 +0000 (+0000) Subject: Simplified assignment to string offset X-Git-Tag: RELEASE_2_0_0a1~942 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=02cbdbe853685eb90d5fb71ba8bf8eab9a1a61e8;p=php Simplified assignment to string offset --- diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 156c31f534..af7a6d1d07 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -669,94 +669,74 @@ static inline void zend_assign_to_string_offset(temp_variable *T, zval *value, i } if (Z_TYPE_P(T->str_offset.str) == IS_STRING) { - zval tmp; - zval *final_value = value; if (((int)T->str_offset.offset < 0)) { zend_error(E_WARNING, "Illegal string offset: %d", T->str_offset.offset); return; } - if (T->str_offset.offset >= Z_STRLEN_P(T->str_offset.str)) { - zend_uint i; - if (Z_STRLEN_P(T->str_offset.str)==0) { - STR_FREE(Z_STRVAL_P(T->str_offset.str)); - Z_STRVAL_P(T->str_offset.str) = (char *) emalloc(T->str_offset.offset+1+1); - } else { - Z_STRVAL_P(T->str_offset.str) = (char *) erealloc(Z_STRVAL_P(T->str_offset.str), T->str_offset.offset+1+1); - } - for (i=Z_STRLEN_P(T->str_offset.str); istr_offset.offset; i++) { - Z_STRVAL_P(T->str_offset.str)[i] = ' '; - } + if (T->str_offset.offset >= Z_STRLEN_P(T->str_offset.str)) { + Z_STRVAL_P(T->str_offset.str) = (char *) erealloc(Z_STRVAL_P(T->str_offset.str), T->str_offset.offset+1+1); + memset(Z_STRVAL_P(T->str_offset.str) + Z_STRLEN_P(T->str_offset.str), + ' ', + T->str_offset.offset - Z_STRLEN_P(T->str_offset.str)); Z_STRVAL_P(T->str_offset.str)[T->str_offset.offset+1] = 0; Z_STRLEN_P(T->str_offset.str) = T->str_offset.offset+1; } if (Z_TYPE_P(value)!=IS_STRING) { - tmp = *value; - if (value_type & (IS_VAR|IS_CV|IS_CONST)) { + zval tmp = *value; + if (value_type != IS_TMP_VAR) { zval_copy_ctor(&tmp); } convert_to_string(&tmp); - final_value = &tmp; - } - - Z_STRVAL_P(T->str_offset.str)[T->str_offset.offset] = Z_STRVAL_P(final_value)[0]; - - if (final_value == &tmp) { - zval_dtor(final_value); - } else if (value_type == IS_TMP_VAR) { - /* we can safely free final_value here - * because separation is done only - * in case value_type == IS_VAR */ - STR_FREE(Z_STRVAL_P(final_value)); + Z_STRVAL_P(T->str_offset.str)[T->str_offset.offset] = Z_STRVAL(tmp)[0]; + STR_FREE(Z_STRVAL(tmp)); + } else { + Z_STRVAL_P(T->str_offset.str)[T->str_offset.offset] = Z_STRVAL_P(value)[0]; + if (value_type == IS_TMP_VAR) { + /* we can safely free final_value here + * because separation is done only + * in case value_type == IS_VAR */ + STR_FREE(Z_STRVAL_P(value)); + } } /* * the value of an assignment to a string offset is undefined T(result->u.var).var = &T->str_offset.str; */ } else if (Z_TYPE_P(T->str_offset.str) == IS_UNICODE) { - zval tmp; - zval *final_value = value; if (((int)T->str_offset.offset < 0)) { zend_error(E_WARNING, "Illegal string offset: %d", T->str_offset.offset); return; } - if (T->str_offset.offset >= Z_USTRLEN_P(T->str_offset.str)) { - zend_uint i; - if (Z_USTRLEN_P(T->str_offset.str)==0) { - USTR_FREE(Z_USTRVAL_P(T->str_offset.str)); - Z_USTRVAL_P(T->str_offset.str) = eumalloc(T->str_offset.offset+1+1); - } else { - Z_USTRVAL_P(T->str_offset.str) = eurealloc(Z_USTRVAL_P(T->str_offset.str), T->str_offset.offset+1+1); - } - for (i=Z_USTRLEN_P(T->str_offset.str); istr_offset.offset; i++) { - Z_USTRVAL_P(T->str_offset.str)[i] = 0x20; /* ' ' */ - } + if (T->str_offset.offset >= Z_USTRLEN_P(T->str_offset.str)) { + Z_USTRVAL_P(T->str_offset.str) = (char *) eurealloc(Z_USTRVAL_P(T->str_offset.str), T->str_offset.offset+1+1); + u_memset(Z_USTRVAL_P(T->str_offset.str) + Z_USTRLEN_P(T->str_offset.str), + ' ', + T->str_offset.offset - Z_USTRLEN_P(T->str_offset.str)); Z_USTRVAL_P(T->str_offset.str)[T->str_offset.offset+1] = 0; Z_USTRLEN_P(T->str_offset.str) = T->str_offset.offset+1; } - if (Z_TYPE_P(value)!=IS_UNICODE) { - tmp = *value; - if (value_type & (IS_VAR|IS_CV|IS_CONST)) { + if (Z_TYPE_P(value) != IS_UNICODE) { + zval tmp = *value; + if (value_type != IS_TMP_VAR) { zval_copy_ctor(&tmp); } convert_to_unicode(&tmp); - final_value = &tmp; - } - - Z_USTRVAL_P(T->str_offset.str)[T->str_offset.offset] = Z_USTRVAL_P(final_value)[0]; - - if (final_value == &tmp) { - zval_dtor(final_value); - } else if (value_type == IS_TMP_VAR) { - /* we can safely free final_value here - * because separation is done only - * in case value_type == IS_VAR */ - USTR_FREE(Z_USTRVAL_P(final_value)); + Z_USTRVAL_P(T->str_offset.str)[T->str_offset.offset] = Z_USTRVAL(tmp)[0]; + USTR_FREE(Z_USTRVAL(tmp)); + } else { + Z_USTRVAL_P(T->str_offset.str)[T->str_offset.offset] = Z_USTRVAL_P(value)[0]; + if (value_type == IS_TMP_VAR) { + /* we can safely free final_value here + * because separation is done only + * in case value_type == IS_VAR */ + USTR_FREE(Z_USTRVAL_P(value)); + } } } }