Skip to content

Commit 006f141

Browse files
authored
ext/phar: Use zend_string_concat2 instead of manual zend_string_alloc/memcpy (php#21441)
1 parent a5ffcf3 commit 006f141

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

ext/phar/stream.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -887,10 +887,10 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from
887887
memcmp(ZSTR_VAL(str_key), ZSTR_VAL(resource_from->path)+1, from_len) == 0 &&
888888
IS_SLASH(ZSTR_VAL(str_key)[from_len])) {
889889

890-
new_str_key = zend_string_alloc(ZSTR_LEN(str_key) + to_len - from_len, 0);
891-
memcpy(ZSTR_VAL(new_str_key), ZSTR_VAL(resource_to->path) + 1, to_len);
892-
memcpy(ZSTR_VAL(new_str_key) + to_len, ZSTR_VAL(str_key) + from_len, ZSTR_LEN(str_key) - from_len);
893-
ZSTR_VAL(new_str_key)[ZSTR_LEN(new_str_key)] = 0;
890+
new_str_key = zend_string_concat2(
891+
ZSTR_VAL(resource_to->path) + 1, to_len,
892+
ZSTR_VAL(str_key) + from_len, ZSTR_LEN(str_key) - from_len
893+
);
894894

895895
is_modified = true;
896896
entry->is_modified = true;
@@ -909,10 +909,10 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from
909909
if (zend_string_starts_with_cstr(str_key, ZSTR_VAL(resource_from->path)+1, from_len) &&
910910
(ZSTR_LEN(str_key) == from_len || IS_SLASH(ZSTR_VAL(str_key)[from_len]))) {
911911

912-
new_str_key = zend_string_alloc(ZSTR_LEN(str_key) + to_len - from_len, 0);
913-
memcpy(ZSTR_VAL(new_str_key), ZSTR_VAL(resource_to->path) + 1, to_len);
914-
memcpy(ZSTR_VAL(new_str_key) + to_len, ZSTR_VAL(str_key) + from_len, ZSTR_LEN(str_key) - from_len);
915-
ZSTR_VAL(new_str_key)[ZSTR_LEN(new_str_key)] = 0;
912+
new_str_key = zend_string_concat2(
913+
ZSTR_VAL(resource_to->path) + 1, to_len,
914+
ZSTR_VAL(str_key) + from_len, ZSTR_LEN(str_key) - from_len
915+
);
916916

917917
zend_string_release_ex(str_key, 0);
918918
b->h = zend_string_hash_val(new_str_key);
@@ -926,10 +926,10 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from
926926
if (zend_string_starts_with_cstr(str_key, ZSTR_VAL(resource_from->path)+1, from_len) &&
927927
(ZSTR_LEN(str_key) == from_len || IS_SLASH(ZSTR_VAL(str_key)[from_len]))) {
928928

929-
new_str_key = zend_string_alloc(ZSTR_LEN(str_key) + to_len - from_len, 0);
930-
memcpy(ZSTR_VAL(new_str_key), ZSTR_VAL(resource_to->path) + 1, to_len);
931-
memcpy(ZSTR_VAL(new_str_key) + to_len, ZSTR_VAL(str_key) + from_len, ZSTR_LEN(str_key) - from_len);
932-
ZSTR_VAL(new_str_key)[ZSTR_LEN(new_str_key)] = 0;
929+
new_str_key = zend_string_concat2(
930+
ZSTR_VAL(resource_to->path) + 1, to_len,
931+
ZSTR_VAL(str_key) + from_len, ZSTR_LEN(str_key) - from_len
932+
);
933933

934934
zend_string_release_ex(str_key, 0);
935935
b->h = zend_string_hash_val(new_str_key);

0 commit comments

Comments
 (0)