summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Zend/zend_compile.c4
-rw-r--r--Zend/zend_execute.c2
-rw-r--r--Zend/zend_ini_parser.y2
-rw-r--r--Zend/zend_language_scanner.c2
-rw-r--r--Zend/zend_language_scanner.l2
-rw-r--r--Zend/zend_operators.c6
-rw-r--r--Zend/zend_string.h84
-rw-r--r--ext/date/php_date.c4
-rw-r--r--ext/iconv/iconv.c6
-rw-r--r--ext/mysqli/mysqli_api.c2
-rw-r--r--ext/oci8/oci8_statement.c2
-rw-r--r--ext/opcache/Optimizer/block_pass.c4
-rw-r--r--ext/pcre/php_pcre.c4
-rw-r--r--ext/pgsql/pgsql.c4
-rw-r--r--ext/reflection/php_reflection.c4
-rw-r--r--ext/sockets/sockets.c2
-rw-r--r--ext/spl/php_spl.c4
-rw-r--r--ext/standard/exec.c4
-rw-r--r--ext/standard/formatted_print.c4
-rw-r--r--ext/standard/metaphone.c4
-rw-r--r--ext/standard/quot_print.c2
-rw-r--r--ext/standard/string.c14
-rw-r--r--ext/standard/url.c4
-rw-r--r--ext/standard/uuencode.c2
-rw-r--r--ext/wddx/wddx.c2
-rw-r--r--ext/xml/xml.c8
-rw-r--r--ext/zlib/zlib.c2
-rw-r--r--main/streams/streams.c4
28 files changed, 114 insertions, 74 deletions
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 962bb14b42..b7c25eea8d 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -1500,7 +1500,7 @@ zend_ast *zend_ast_append_str(zend_ast *left_ast, zend_ast *right_ast) /* {{{ */
size_t left_len = left->len;
size_t len = left_len + right->len + 1; /* left\right */
- result = zend_string_realloc(left, len, 0);
+ result = zend_string_extend(left, len, 0);
result->val[left_len] = '\\';
memcpy(&result->val[left_len + 1], right->val, right->len);
result->val[len] = '\0';
@@ -5225,7 +5225,7 @@ static zend_bool zend_try_ct_eval_magic_const(zval *zv, zend_ast *ast) /* {{{ */
zend_dirname(dirname->val, dirname->len);
if (strcmp(dirname->val, ".") == 0) {
- dirname = zend_string_realloc(dirname, MAXPATHLEN, 0);
+ dirname = zend_string_extend(dirname, MAXPATHLEN, 0);
#if HAVE_GETCWD
VCWD_GETCWD(dirname->val, MAXPATHLEN);
#elif HAVE_GETWD
diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c
index 1692baa999..caaeb6a5fd 100644
--- a/Zend/zend_execute.c
+++ b/Zend/zend_execute.c
@@ -1136,7 +1136,7 @@ static void zend_assign_to_string_offset(zval *str, zend_long offset, zval *valu
old_str = Z_STR_P(str);
if ((size_t)offset >= Z_STRLEN_P(str)) {
zend_long old_len = Z_STRLEN_P(str);
- Z_STR_P(str) = zend_string_realloc(Z_STR_P(str), offset + 1, 0);
+ Z_STR_P(str) = zend_string_extend(Z_STR_P(str), offset + 1, 0);
Z_TYPE_INFO_P(str) = IS_STRING_EX;
memset(Z_STRVAL_P(str) + old_len, ' ', offset - old_len);
Z_STRVAL_P(str)[offset+1] = 0;
diff --git a/Zend/zend_ini_parser.y b/Zend/zend_ini_parser.y
index f9c8581ab9..572d70f248 100644
--- a/Zend/zend_ini_parser.y
+++ b/Zend/zend_ini_parser.y
@@ -105,7 +105,7 @@ static void zend_ini_add_string(zval *result, zval *op1, zval *op2)
int op1_len = (int)Z_STRLEN_P(op1);
int length = op1_len + (int)Z_STRLEN_P(op2);
- ZVAL_NEW_STR(result, zend_string_realloc(Z_STR_P(op1), length, 1));
+ ZVAL_NEW_STR(result, zend_string_extend(Z_STR_P(op1), length, 1));
memcpy(Z_STRVAL_P(result)+op1_len, Z_STRVAL_P(op2), Z_STRLEN_P(op2));
Z_STRVAL_P(result)[length] = 0;
}
diff --git a/Zend/zend_language_scanner.c b/Zend/zend_language_scanner.c
index 3ddf7e86c3..edde9ca870 100644
--- a/Zend/zend_language_scanner.c
+++ b/Zend/zend_language_scanner.c
@@ -657,7 +657,7 @@ ZEND_API int zend_prepare_string_for_scanning(zval *str, char *filename)
/* enforce ZEND_MMAP_AHEAD trailing NULLs for flex... */
old_len = Z_STRLEN_P(str);
- Z_STR_P(str) = zend_string_realloc(Z_STR_P(str), old_len + ZEND_MMAP_AHEAD, 0);
+ Z_STR_P(str) = zend_string_extend(Z_STR_P(str), old_len + ZEND_MMAP_AHEAD, 0);
Z_TYPE_INFO_P(str) = IS_STRING_EX;
memset(Z_STRVAL_P(str) + old_len, 0, ZEND_MMAP_AHEAD + 1);
diff --git a/Zend/zend_language_scanner.l b/Zend/zend_language_scanner.l
index 5cf83f506b..941a6cbcea 100644
--- a/Zend/zend_language_scanner.l
+++ b/Zend/zend_language_scanner.l
@@ -655,7 +655,7 @@ ZEND_API int zend_prepare_string_for_scanning(zval *str, char *filename)
/* enforce ZEND_MMAP_AHEAD trailing NULLs for flex... */
old_len = Z_STRLEN_P(str);
- Z_STR_P(str) = zend_string_realloc(Z_STR_P(str), old_len + ZEND_MMAP_AHEAD, 0);
+ Z_STR_P(str) = zend_string_extend(Z_STR_P(str), old_len + ZEND_MMAP_AHEAD, 0);
Z_TYPE_INFO_P(str) = IS_STRING_EX;
memset(Z_STRVAL_P(str) + old_len, 0, ZEND_MMAP_AHEAD + 1);
diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c
index d8e92a97ad..8a58f3791e 100644
--- a/Zend/zend_operators.c
+++ b/Zend/zend_operators.c
@@ -1501,7 +1501,7 @@ ZEND_API int ZEND_FASTCALL shift_right_function(zval *result, zval *op1, zval *o
ZEND_API int ZEND_FASTCALL add_char_to_string(zval *result, const zval *op1, const zval *op2) /* {{{ */
{
size_t length = Z_STRLEN_P(op1) + 1;
- zend_string *buf = zend_string_realloc(Z_STR_P(op1), length, 0);
+ zend_string *buf = zend_string_extend(Z_STR_P(op1), length, 0);
buf->val[length - 1] = (char) Z_LVAL_P(op2);
buf->val[length] = 0;
@@ -1515,7 +1515,7 @@ ZEND_API int ZEND_FASTCALL add_string_to_string(zval *result, const zval *op1, c
{
size_t op1_len = Z_STRLEN_P(op1);
size_t length = op1_len + Z_STRLEN_P(op2);
- zend_string *buf = zend_string_realloc(Z_STR_P(op1), length, 0);
+ zend_string *buf = zend_string_extend(Z_STR_P(op1), length, 0);
memcpy(buf->val + op1_len, Z_STRVAL_P(op2), Z_STRLEN_P(op2));
buf->val[length] = 0;
@@ -1577,7 +1577,7 @@ ZEND_API int ZEND_FASTCALL concat_function(zval *result, zval *op1, zval *op2) /
if (result == op1 && Z_REFCOUNTED_P(result)) {
/* special case, perform operations on result */
- result_str = zend_string_realloc(Z_STR_P(result), result_len, 0);
+ result_str = zend_string_extend(Z_STR_P(result), result_len, 0);
} else {
result_str = zend_string_alloc(result_len, 0);
memcpy(result_str->val, Z_STRVAL_P(op1), op1_len);
diff --git a/Zend/zend_string.h b/Zend/zend_string.h
index b7605efc09..29985b7335 100644
--- a/Zend/zend_string.h
+++ b/Zend/zend_string.h
@@ -158,18 +158,58 @@ static zend_always_inline zend_string *zend_string_realloc(zend_string *s, size_
{
zend_string *ret;
- if (IS_INTERNED(s)) {
- ret = zend_string_alloc(len, persistent);
- memcpy(ret->val, s->val, (len > s->len ? s->len : len) + 1);
- } else if (EXPECTED(GC_REFCOUNT(s) == 1)) {
- ret = (zend_string *)perealloc(s, ZEND_MM_ALIGNED_SIZE(_STR_HEADER_SIZE + len + 1), persistent);
- ret->len = len;
- zend_string_forget_hash_val(ret);
- } else {
- ret = zend_string_alloc(len, persistent);
- memcpy(ret->val, s->val, (len > s->len ? s->len : len) + 1);
- GC_REFCOUNT(s)--;
+ if (!IS_INTERNED(s)) {
+ if (EXPECTED(GC_REFCOUNT(s) == 1)) {
+ ret = (zend_string *)perealloc(s, ZEND_MM_ALIGNED_SIZE(_STR_HEADER_SIZE + len + 1), persistent);
+ ret->len = len;
+ zend_string_forget_hash_val(ret);
+ return ret;
+ } else {
+ GC_REFCOUNT(s)--;
+ }
+ }
+ ret = zend_string_alloc(len, persistent);
+ memcpy(ret->val, s->val, (len > s->len ? s->len : len) + 1);
+ return ret;
+}
+
+static zend_always_inline zend_string *zend_string_extend(zend_string *s, size_t len, int persistent)
+{
+ zend_string *ret;
+
+ ZEND_ASSERT(len >= s->len);
+ if (!IS_INTERNED(s)) {
+ if (EXPECTED(GC_REFCOUNT(s) == 1)) {
+ ret = (zend_string *)perealloc(s, ZEND_MM_ALIGNED_SIZE(_STR_HEADER_SIZE + len + 1), persistent);
+ ret->len = len;
+ zend_string_forget_hash_val(ret);
+ return ret;
+ } else {
+ GC_REFCOUNT(s)--;
+ }
}
+ ret = zend_string_alloc(len, persistent);
+ memcpy(ret->val, s->val, s->len + 1);
+ return ret;
+}
+
+static zend_always_inline zend_string *zend_string_truncate(zend_string *s, size_t len, int persistent)
+{
+ zend_string *ret;
+
+ ZEND_ASSERT(len <= s->len);
+ if (!IS_INTERNED(s)) {
+ if (EXPECTED(GC_REFCOUNT(s) == 1)) {
+ ret = (zend_string *)perealloc(s, ZEND_MM_ALIGNED_SIZE(_STR_HEADER_SIZE + len + 1), persistent);
+ ret->len = len;
+ zend_string_forget_hash_val(ret);
+ return ret;
+ } else {
+ GC_REFCOUNT(s)--;
+ }
+ }
+ ret = zend_string_alloc(len, persistent);
+ memcpy(ret->val, s->val, len + 1);
return ret;
}
@@ -177,18 +217,18 @@ static zend_always_inline zend_string *zend_string_safe_realloc(zend_string *s,
{
zend_string *ret;
- if (IS_INTERNED(s)) {
- ret = zend_string_safe_alloc(n, m, l, persistent);
- memcpy(ret->val, s->val, ((n * m) + l > (size_t)s->len ? (size_t)s->len : ((n * m) + l)) + 1);
- } else if (GC_REFCOUNT(s) == 1) {
- ret = (zend_string *)safe_perealloc(s, n, m, ZEND_MM_ALIGNED_SIZE(_STR_HEADER_SIZE + l + 1), persistent);
- ret->len = (n * m) + l;
- zend_string_forget_hash_val(ret);
- } else {
- ret = zend_string_safe_alloc(n, m, l, persistent);
- memcpy(ret->val, s->val, ((n * m) + l > (size_t)s->len ? (size_t)s->len : ((n * m) + l)) + 1);
- GC_REFCOUNT(s)--;
+ if (!IS_INTERNED(s)) {
+ if (GC_REFCOUNT(s) == 1) {
+ ret = (zend_string *)safe_perealloc(s, n, m, ZEND_MM_ALIGNED_SIZE(_STR_HEADER_SIZE + l + 1), persistent);
+ ret->len = (n * m) + l;
+ zend_string_forget_hash_val(ret);
+ return ret;
+ } else {
+ GC_REFCOUNT(s)--;
+ }
}
+ ret = zend_string_safe_alloc(n, m, l, persistent);
+ memcpy(ret->val, s->val, ((n * m) + l > s->len ? s->len : ((n * m) + l)) + 1);
return ret;
}
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index 1946dacda1..3df1669c40 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -1661,7 +1661,7 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt)
buf = zend_string_alloc(buf_len, 0);
while ((real_len = strftime(buf->val, buf_len, format, &ta)) == buf_len || real_len == 0) {
buf_len *= 2;
- buf = zend_string_realloc(buf, buf_len, 0);
+ buf = zend_string_extend(buf, buf_len, 0);
if (!--max_reallocs) {
break;
}
@@ -1680,7 +1680,7 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt)
}
if (real_len && real_len != buf_len) {
- buf = zend_string_realloc(buf, real_len, 0);
+ buf = zend_string_truncate(buf, real_len, 0);
RETURN_NEW_STR(buf);
}
zend_string_free(buf);
diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c
index 81dfd51136..7621ce75ac 100644
--- a/ext/iconv/iconv.c
+++ b/ext/iconv/iconv.c
@@ -581,7 +581,7 @@ PHP_ICONV_API php_iconv_err_t php_iconv_string(const char *in_p, size_t in_len,
if (out_left < 8) {
size_t pos = out_p - out_buffer->val;
- out_buffer = zend_string_realloc(out_buffer, out_size + 8, 0);
+ out_buffer = zend_string_extend(out_buffer, out_size + 8, 0);
out_p = out_buffer->val + pos;
out_size += 7;
out_left += 7;
@@ -640,7 +640,7 @@ PHP_ICONV_API php_iconv_err_t php_iconv_string(const char *in_p, size_t in_len,
/* converted string is longer than out buffer */
bsz += in_len;
- out_buf = zend_string_realloc(out_buf, bsz, 0);
+ out_buf = zend_string_extend(out_buf, bsz, 0);
out_p = out_buf->val;
out_p += out_size;
out_left = bsz - out_size;
@@ -662,7 +662,7 @@ PHP_ICONV_API php_iconv_err_t php_iconv_string(const char *in_p, size_t in_len,
if (errno == E2BIG) {
bsz += 16;
- out_buf = zend_string_realloc(out_buf, bsz, 0);
+ out_buf = zend_string_extend(out_buf, bsz, 0);
out_p = out_buf->val;
out_p += out_size;
out_left = bsz - out_size;
diff --git a/ext/mysqli/mysqli_api.c b/ext/mysqli/mysqli_api.c
index eec5e74acb..d19126ff91 100644
--- a/ext/mysqli/mysqli_api.c
+++ b/ext/mysqli/mysqli_api.c
@@ -1988,7 +1988,7 @@ PHP_FUNCTION(mysqli_real_escape_string) {
newstr = zend_string_alloc(2 * escapestr_len, 0);
newstr->len = mysql_real_escape_string(mysql->mysql, newstr->val, escapestr, escapestr_len);
- newstr = zend_string_realloc(newstr, newstr->len, 0);
+ newstr = zend_string_truncate(newstr, newstr->len, 0);
RETURN_NEW_STR(newstr);
}
diff --git a/ext/oci8/oci8_statement.c b/ext/oci8/oci8_statement.c
index 4fcff43c4f..d55de3275e 100644
--- a/ext/oci8/oci8_statement.c
+++ b/ext/oci8/oci8_statement.c
@@ -983,7 +983,7 @@ int php_oci_bind_post_exec(void *data)
* binds, php_oci_bind_out_callback() should have allocated a
* new string that we can modify here.
*/
- Z_STR(bind->zval) = zend_string_realloc(Z_STR(bind->zval), Z_STRLEN(bind->zval)+1, 0);
+ Z_STR(bind->zval) = zend_string_extend(Z_STR(bind->zval), Z_STRLEN(bind->zval)+1, 0);
Z_STRVAL(bind->zval)[ Z_STRLEN(bind->zval) ] = '\0';
} else if (Z_TYPE(bind->zval) == IS_ARRAY) {
int i;
diff --git a/ext/opcache/Optimizer/block_pass.c b/ext/opcache/Optimizer/block_pass.c
index 24be4d266a..3f57183ed3 100644
--- a/ext/opcache/Optimizer/block_pass.c
+++ b/ext/opcache/Optimizer/block_pass.c
@@ -899,7 +899,7 @@ static void zend_optimize_block(zend_code_block *block, zend_op_array *op_array,
memcpy(tmp->val, Z_STRVAL(ZEND_OP1_LITERAL(last_op)), old_len);
Z_STR(ZEND_OP1_LITERAL(last_op)) = tmp;
} else {
- Z_STR(ZEND_OP1_LITERAL(last_op)) = zend_string_realloc(Z_STR(ZEND_OP1_LITERAL(last_op)), l, 0);
+ Z_STR(ZEND_OP1_LITERAL(last_op)) = zend_string_extend(Z_STR(ZEND_OP1_LITERAL(last_op)), l, 0);
}
Z_TYPE_INFO(ZEND_OP1_LITERAL(last_op)) = IS_STRING_EX;
memcpy(Z_STRVAL(ZEND_OP1_LITERAL(last_op)) + old_len, Z_STRVAL(ZEND_OP1_LITERAL(opline)), Z_STRLEN(ZEND_OP1_LITERAL(opline)));
@@ -954,7 +954,7 @@ static void zend_optimize_block(zend_code_block *block, zend_op_array *op_array,
memcpy(tmp->val, Z_STRVAL(ZEND_OP2_LITERAL(src)), old_len);
Z_STR(ZEND_OP2_LITERAL(last_op)) = tmp;
} else {
- Z_STR(ZEND_OP2_LITERAL(src)) = zend_string_realloc(Z_STR(ZEND_OP2_LITERAL(src)), l, 0);
+ Z_STR(ZEND_OP2_LITERAL(src)) = zend_string_extend(Z_STR(ZEND_OP2_LITERAL(src)), l, 0);
}
Z_TYPE_INFO(ZEND_OP2_LITERAL(last_op)) = IS_STRING_EX;
memcpy(Z_STRVAL(ZEND_OP2_LITERAL(src)) + old_len, Z_STRVAL(ZEND_OP2_LITERAL(opline)), Z_STRLEN(ZEND_OP2_LITERAL(opline)));
diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c
index 6e769e06f0..8080823b09 100644
--- a/ext/pcre/php_pcre.c
+++ b/ext/pcre/php_pcre.c
@@ -1158,7 +1158,7 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, zend_string *su
result = zend_string_alloc(alloc_len, 0);
} else {
alloc_len = alloc_len + 2 * new_len;
- result = zend_string_realloc(result, alloc_len, 0);
+ result = zend_string_extend(result, alloc_len, 0);
}
}
/* copy the part of the string before the match */
@@ -1779,7 +1779,7 @@ static PHP_FUNCTION(preg_quote)
*q = '\0';
/* Reallocate string and return it */
- out_str = zend_string_realloc(out_str, q - out_str->val, 0);
+ out_str = zend_string_truncate(out_str, q - out_str->val, 0);
RETURN_NEW_STR(out_str);
}
/* }}} */
diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c
index 4cbd218450..6e37f18287 100644
--- a/ext/pgsql/pgsql.c
+++ b/ext/pgsql/pgsql.c
@@ -4362,7 +4362,7 @@ PHP_FUNCTION(pg_escape_string)
to->len = PQescapeString(to->val, from->val, from->len);
}
- to = zend_string_realloc(to, to->len, 0);
+ to = zend_string_truncate(to, to->len, 0);
RETURN_NEW_STR(to);
}
/* }}} */
@@ -6048,7 +6048,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
str = zend_string_alloc(Z_STRLEN_P(val) * 2, 0);
/* better to use PGSQLescapeLiteral since PGescapeStringConn does not handle special \ */
str->len = PQescapeStringConn(pg_link, str->val, Z_STRVAL_P(val), Z_STRLEN_P(val), NULL);
- str = zend_string_realloc(str, str->len, 0);
+ str = zend_string_truncate(str, str->len, 0);
ZVAL_NEW_STR(&new_val, str);
php_pgsql_add_quotes(&new_val, 1);
}
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index bed3823a4e..72a88be47c 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -140,7 +140,7 @@ static string *string_printf(string *str, const char *format, ...)
if (str->alloced < nlen) {
size_t old_len = str->buf->len;
str->alloced = nlen;
- str->buf = zend_string_realloc(str->buf, str->alloced, 0);
+ str->buf = zend_string_extend(str->buf, str->alloced, 0);
str->buf->len = old_len;
}
memcpy(str->buf->val + str->buf->len, s_tmp, len + 1);
@@ -157,7 +157,7 @@ static string *string_write(string *str, char *buf, size_t len)
if (str->alloced < nlen) {
size_t old_len = str->buf->len;
str->alloced = nlen;
- str->buf = zend_string_realloc(str->buf, str->alloced, 0);
+ str->buf = zend_string_extend(str->buf, str->alloced, 0);
str->buf->len = old_len;
}
memcpy(str->buf->val + str->buf->len, buf, len);
diff --git a/ext/sockets/sockets.c b/ext/sockets/sockets.c
index 32172c803b..5f6c17af9a 100644
--- a/ext/sockets/sockets.c
+++ b/ext/sockets/sockets.c
@@ -1177,7 +1177,7 @@ PHP_FUNCTION(socket_read)
RETURN_EMPTY_STRING();
}
- tmpbuf = zend_string_realloc(tmpbuf, retval, 0);
+ tmpbuf = zend_string_truncate(tmpbuf, retval, 0);
tmpbuf->len = retval;
tmpbuf->val[tmpbuf->len] = '\0' ;
diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c
index f16734422b..78bdd6744f 100644
--- a/ext/spl/php_spl.c
+++ b/ext/spl/php_spl.c
@@ -552,7 +552,7 @@ PHP_FUNCTION(spl_autoload_register)
if (obj_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) {
/* add object id to the hash to ensure uniqueness, for more reference look at bug #40091 */
- lc_name = zend_string_realloc(lc_name, lc_name->len + sizeof(uint32_t), 0);
+ lc_name = zend_string_extend(lc_name, lc_name->len + sizeof(uint32_t), 0);
memcpy(lc_name->val + lc_name->len - sizeof(uint32_t), &obj_ptr->handle, sizeof(uint32_t));
lc_name->val[lc_name->len] = '\0';
ZVAL_OBJ(&alfi.obj, obj_ptr);
@@ -663,7 +663,7 @@ PHP_FUNCTION(spl_autoload_unregister)
/* remove specific */
success = zend_hash_del(SPL_G(autoload_functions), lc_name);
if (success != SUCCESS && obj_ptr) {
- lc_name = zend_string_realloc(lc_name, lc_name->len + sizeof(uint32_t), 0);
+ lc_name = zend_string_extend(lc_name, lc_name->len + sizeof(uint32_t), 0);
memcpy(lc_name->val + lc_name->len - sizeof(uint32_t), &obj_ptr->handle, sizeof(uint32_t));
lc_name->val[lc_name->len] = '\0';
success = zend_hash_del(SPL_G(autoload_functions), lc_name);
diff --git a/ext/standard/exec.c b/ext/standard/exec.c
index a98751ef12..71dfc7c361 100644
--- a/ext/standard/exec.c
+++ b/ext/standard/exec.c
@@ -326,7 +326,7 @@ PHPAPI zend_string *php_escape_shell_cmd(char *str)
if ((estimate - y) > 4096) {
/* realloc if the estimate was way overill
* Arbitrary cutoff point of 4096 */
- cmd = zend_string_realloc(cmd, y, 0);
+ cmd = zend_string_truncate(cmd, y, 0);
}
cmd->len = y;
@@ -392,7 +392,7 @@ PHPAPI zend_string *php_escape_shell_arg(char *str)
if ((estimate - y) > 4096) {
/* realloc if the estimate was way overill
* Arbitrary cutoff point of 4096 */
- cmd = zend_string_realloc(cmd, y, 0);
+ cmd = zend_string_truncate(cmd, y, 0);
}
cmd->len = y;
return cmd;
diff --git a/ext/standard/formatted_print.c b/ext/standard/formatted_print.c
index cf4eee0657..4c0eeeebb9 100644
--- a/ext/standard/formatted_print.c
+++ b/ext/standard/formatted_print.c
@@ -61,7 +61,7 @@ php_sprintf_appendchar(zend_string **buffer, size_t *pos, char add)
{
if (!*buffer || (*pos + 1) >= (*buffer)->len) {
PRINTF_DEBUG(("%s(): ereallocing buffer to %d bytes\n", get_active_function_name(), (*buffer)->len));
- *buffer = zend_string_realloc(*buffer, (*buffer)->len << 1, 0);
+ *buffer = zend_string_extend(*buffer, (*buffer)->len << 1, 0);
}
PRINTF_DEBUG(("sprintf: appending '%c', pos=\n", add, *pos));
(*buffer)->val[(*pos)++] = add;
@@ -101,7 +101,7 @@ php_sprintf_appendstring(zend_string **buffer, size_t *pos, char *add,
size <<= 1;
}
PRINTF_DEBUG(("sprintf ereallocing buffer to %d bytes\n", size));
- *buffer = zend_string_realloc(*buffer, size, 0);
+ *buffer = zend_string_extend(*buffer, size, 0);
}
if (alignment == ALIGN_RIGHT) {
if ((neg || always_sign) && padding=='0') {
diff --git a/ext/standard/metaphone.c b/ext/standard/metaphone.c
index cc94b0372f..de29415cdf 100644
--- a/ext/standard/metaphone.c
+++ b/ext/standard/metaphone.c
@@ -142,7 +142,7 @@ static char Lookahead(char *word, int how_far)
* could be one though; or more too). */
#define Phonize(c) { \
if (p_idx >= max_buffer_len) { \
- *phoned_word = zend_string_realloc(*phoned_word, 2 * sizeof(char) + max_buffer_len, 0); \
+ *phoned_word = zend_string_extend(*phoned_word, 2 * sizeof(char) + max_buffer_len, 0); \
max_buffer_len += 2; \
} \
(*phoned_word)->val[p_idx++] = c; \
@@ -151,7 +151,7 @@ static char Lookahead(char *word, int how_far)
/* Slap a null character on the end of the phoned word */
#define End_Phoned_Word { \
if (p_idx == max_buffer_len) { \
- *phoned_word = zend_string_realloc(*phoned_word, 1 * sizeof(char) + max_buffer_len, 0); \
+ *phoned_word = zend_string_extend(*phoned_word, 1 * sizeof(char) + max_buffer_len, 0); \
max_buffer_len += 1; \
} \
(*phoned_word)->val[p_idx] = '\0'; \
diff --git a/ext/standard/quot_print.c b/ext/standard/quot_print.c
index d19ef07e66..26d1d2b6fc 100644
--- a/ext/standard/quot_print.c
+++ b/ext/standard/quot_print.c
@@ -187,7 +187,7 @@ PHPAPI zend_string *php_quot_print_encode(const unsigned char *str, size_t lengt
}
}
*d = '\0';
- ret = zend_string_realloc(ret, d - (unsigned char*)ret->val, 0);
+ ret = zend_string_truncate(ret, d - (unsigned char*)ret->val, 0);
return ret;
}
/* }}} */
diff --git a/ext/standard/string.c b/ext/standard/string.c
index fbbb639dc2..01a87fe919 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -1004,7 +1004,7 @@ PHP_FUNCTION(wordwrap)
for (current = 0; current < text->len; current++) {
if (chk <= 0) {
alloced += (size_t) (((text->len - current + 1)/linelength + 1) * breakchar_len) + 1;
- newtext = zend_string_realloc(newtext, alloced, 0);
+ newtext = zend_string_extend(newtext, alloced, 0);
chk = (size_t) ((text->len - current)/linelength) + 1;
}
/* when we hit an existing break, copy to new buffer, and
@@ -1065,7 +1065,7 @@ PHP_FUNCTION(wordwrap)
newtext->val[newtextlen] = '\0';
/* free unused memory */
- newtext = zend_string_realloc(newtext, newtextlen, 0);
+ newtext = zend_string_truncate(newtext, newtextlen, 0);
RETURN_NEW_STR(newtext);
}
@@ -2738,7 +2738,7 @@ PHP_FUNCTION(quotemeta)
*q = '\0';
- RETURN_NEW_STR(zend_string_realloc(str, q - str->val, 0));
+ RETURN_NEW_STR(zend_string_truncate(str, q - str->val, 0));
}
/* }}} */
@@ -3441,7 +3441,7 @@ PHPAPI zend_string *php_str_to_str(char *haystack, size_t length, char *needle,
}
*e = '\0';
- new_str = zend_string_realloc(new_str, e - s, 0);
+ new_str = zend_string_truncate(new_str, e - s, 0);
return new_str;
}
} else if (needle_len > length || memcmp(haystack, needle, length)) {
@@ -3878,7 +3878,7 @@ PHPAPI zend_string *php_addcslashes(zend_string *str, int should_free, char *wha
*target = 0;
newlen = target - new_str->val;
if (newlen < str->len * 4) {
- new_str = zend_string_realloc(new_str, newlen, 0);
+ new_str = zend_string_truncate(new_str, newlen, 0);
}
if (should_free) {
zend_string_release(str);
@@ -3954,7 +3954,7 @@ do_escape:
}
if (new_str->len - (target - new_str->val) > 16) {
- new_str = zend_string_realloc(new_str, target - new_str->val, 0);
+ new_str = zend_string_truncate(new_str, target - new_str->val, 0);
} else {
new_str->len = target - new_str->val;
}
@@ -5648,7 +5648,7 @@ PHP_FUNCTION(money_format)
str->len = (size_t)res_len;
str->val[str->len] = '\0';
- RETURN_NEW_STR(zend_string_realloc(str, str->len, 0));
+ RETURN_NEW_STR(zend_string_truncate(str, str->len, 0));
}
/* }}} */
#endif
diff --git a/ext/standard/url.c b/ext/standard/url.c
index b2ffa3750e..1dceda1483 100644
--- a/ext/standard/url.c
+++ b/ext/standard/url.c
@@ -524,7 +524,7 @@ PHPAPI zend_string *php_url_encode(char const *s, size_t len)
}
*to = '\0';
- start = zend_string_realloc(start, to - (unsigned char*)start->val, 0);
+ start = zend_string_truncate(start, to - (unsigned char*)start->val, 0);
return start;
}
@@ -631,7 +631,7 @@ PHPAPI zend_string *php_raw_url_encode(char const *s, size_t len)
}
}
str->val[y] = '\0';
- str = zend_string_realloc(str, y, 0);
+ str = zend_string_truncate(str, y, 0);
return str;
}
diff --git a/ext/standard/uuencode.c b/ext/standard/uuencode.c
index afe9f7bea1..91de87a194 100644
--- a/ext/standard/uuencode.c
+++ b/ext/standard/uuencode.c
@@ -122,7 +122,7 @@ PHPAPI zend_string *php_uuencode(char *src, size_t src_len) /* {{{ */
*p++ = '\n';
*p = '\0';
- dest = zend_string_realloc(dest, p - dest->val, 0);
+ dest = zend_string_truncate(dest, p - dest->val, 0);
return dest;
}
/* }}} */
diff --git a/ext/wddx/wddx.c b/ext/wddx/wddx.c
index 371b1e95d1..235efcdd18 100644
--- a/ext/wddx/wddx.c
+++ b/ext/wddx/wddx.c
@@ -991,7 +991,7 @@ static void php_wddx_process_data(void *user_data, const XML_Char *s, int len)
zval_ptr_dtor(&ent->data);
ZVAL_STRINGL(&ent->data, (char *)s, len);
} else {
- Z_STR(ent->data) = zend_string_realloc(Z_STR(ent->data), Z_STRLEN(ent->data) + len, 0);
+ Z_STR(ent->data) = zend_string_extend(Z_STR(ent->data), Z_STRLEN(ent->data) + len, 0);
memcpy(Z_STRVAL(ent->data) + Z_STRLEN(ent->data) - len, (char *)s, len);
Z_STRVAL(ent->data)[Z_STRLEN(ent->data)] = '\0';
}
diff --git a/ext/xml/xml.c b/ext/xml/xml.c
index 0ced7a2284..8a26a7ff5c 100644
--- a/ext/xml/xml.c
+++ b/ext/xml/xml.c
@@ -604,7 +604,7 @@ PHPAPI zend_string *xml_utf8_encode(const char *s, size_t len, const XML_Char *e
s++;
}
str->val[str->len] = '\0';
- str = zend_string_realloc(str, str->len, 0);
+ str = zend_string_truncate(str, str->len, 0);
return str;
}
/* }}} */
@@ -644,7 +644,7 @@ PHPAPI zend_string *xml_utf8_decode(const XML_Char *s, size_t len, const XML_Cha
}
str->val[str->len] = '\0';
if (str->len < len) {
- str = zend_string_realloc(str, str->len, 0);
+ str = zend_string_truncate(str, str->len, 0);
}
return str;
@@ -892,7 +892,7 @@ void _xml_characterDataHandler(void *userData, const XML_Char *s, int len)
/* check if the current tag already has a value - if yes append to that! */
if ((myval = zend_hash_str_find(Z_ARRVAL_P(parser->ctag), "value", sizeof("value") - 1))) {
int newlen = Z_STRLEN_P(myval) + decoded_value->len;
- Z_STR_P(myval) = zend_string_realloc(Z_STR_P(myval), newlen, 0);
+ Z_STR_P(myval) = zend_string_extend(Z_STR_P(myval), newlen, 0);
strncpy(Z_STRVAL_P(myval) + Z_STRLEN_P(myval) - decoded_value->len,
decoded_value->val, decoded_value->len + 1);
zend_string_release(decoded_value);
@@ -909,7 +909,7 @@ void _xml_characterDataHandler(void *userData, const XML_Char *s, int len)
if (!strcmp(Z_STRVAL_P(mytype), "cdata")) {
if ((myval = zend_hash_str_find(Z_ARRVAL_P(curtag), "value", sizeof("value") - 1))) {
int newlen = Z_STRLEN_P(myval) + decoded_value->len;
- Z_STR_P(myval) = zend_string_realloc(Z_STR_P(myval), newlen, 0);
+ Z_STR_P(myval) = zend_string_extend(Z_STR_P(myval), newlen, 0);
strncpy(Z_STRVAL_P(myval) + Z_STRLEN_P(myval) - decoded_value->len,
decoded_value->val, decoded_value->len + 1);
zend_string_release(decoded_value);
diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c
index 64eac450cd..b638ab4377 100644
--- a/ext/zlib/zlib.c
+++ b/ext/zlib/zlib.c
@@ -336,7 +336,7 @@ static zend_string *php_zlib_encode(const char *in_buf, size_t in_len, int encod
if (Z_STREAM_END == status) {
/* size buffer down to actual length */
- out = zend_string_realloc(out, Z.total_out, 0);
+ out = zend_string_truncate(out, Z.total_out, 0);
out->val[out->len] = '\0';
return out;
} else {
diff --git a/main/streams/streams.c b/main/streams/streams.c
index 64b5470738..0e95544fc1 100644
--- a/main/streams/streams.c
+++ b/main/streams/streams.c
@@ -1477,7 +1477,7 @@ PHPAPI zend_string *_php_stream_copy_to_mem(php_stream *src, size_t maxlen, int
while ((ret = php_stream_read(src, ptr, max_len - len))) {
len += ret;
if (len + min_room >= max_len) {
- result = zend_string_realloc(result, max_len + step, persistent);
+ result = zend_string_extend(result, max_len + step, persistent);
max_len += step;
ptr = result->val + len;
} else {
@@ -1485,7 +1485,7 @@ PHPAPI zend_string *_php_stream_copy_to_mem(php_stream *src, size_t maxlen, int
}
}
if (len) {
- result = zend_string_realloc(result, len, persistent);
+ result = zend_string_truncate(result, len, persistent);
result->val[len] = '\0';
} else {
zend_string_free(result);