Skip to content

Commit f33bdd3

Browse files
GermanAizeknmoinvaz
authored andcommitted
Pre-calc length destination directory before while loop
1 parent 581a403 commit f33bdd3

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

mz_zip_rw.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,7 @@ int32_t mz_zip_reader_save_all(void *handle, const char *destination_dir) {
815815
int32_t err = MZ_OK;
816816
int32_t utf8_name_size = 0;
817817
int32_t resolved_name_size = 0;
818+
int32_t destination_dir_len = 0;
818819
char *utf8_string = NULL;
819820
char *path = NULL;
820821
char *utf8_name = NULL;
@@ -826,14 +827,15 @@ int32_t mz_zip_reader_save_all(void *handle, const char *destination_dir) {
826827
if (err == MZ_END_OF_LIST)
827828
return err;
828829

830+
destination_dir_len = (int32_t)strlen(destination_dir) + 1;
829831
while (err == MZ_OK) {
830832
/* Assume 4 bytes per character needed + 1 for terminating null */
831833
utf8_name_size = reader->file_info->filename_size * 4 + 1;
832834
resolved_name_size = utf8_name_size;
833835

834836
if (destination_dir) {
835837
/* +1 is for the "/" separator */
836-
resolved_name_size += (int)strlen(destination_dir) + 1;
838+
resolved_name_size += destination_dir_len;
837839
}
838840

839841
new_alloc = (char *)realloc(path, resolved_name_size);

0 commit comments

Comments
 (0)