Skip to content

Commit 7d5847d

Browse files
authored
ext/zip: Preinitialize arrays when size is known (php#21572)
1 parent 3080507 commit 7d5847d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

ext/zip/php_zip.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ int php_zip_glob(zend_string *spattern, zend_long flags, zval *return_value) /*
709709
return -1;
710710
}
711711

712-
array_init(return_value);
712+
array_init_size(return_value, (uint32_t)globbuf.gl_pathc);
713713
for (size_t n = 0; n < globbuf.gl_pathc; n++) {
714714
/* we need to do this every time since PHP_GLOB_ONLYDIR does not guarantee that
715715
* all directories will be filtered. GNU libc documentation states the
@@ -788,7 +788,7 @@ int php_zip_pcre(zend_string *regexp, char *path, int path_len, zval *return_val
788788
return -1;
789789
}
790790

791-
array_init(return_value);
791+
array_init_size(return_value, (uint32_t)files_cnt);
792792

793793
/* only the files, directories are ignored */
794794
for (i = 0; i < files_cnt; i++) {

0 commit comments

Comments
 (0)