Skip to content

Make pattern in mz_zip_reader dynamically assigned #856

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 16, 2025

Conversation

DreamHelium
Copy link
Contributor

Since pattern should be used along with the usage of functions like mz_zip_reader_goto_next_entry, and one could put a dynamically-assigned pattern in another function, which makes it difficult to free the original string, there's need to make the pattern in mz_zip_reader dynamically assigned, and the old string can be freed immediately.

mz_zip_rw.c Outdated
return;
free(reader->pattern);
reader->pattern = NULL;
if(pattern)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space after if

mz_zip_rw.c Outdated
@@ -905,7 +910,19 @@ int32_t mz_zip_reader_save_all(void *handle, const char *destination_dir) {

void mz_zip_reader_set_pattern(void *handle, const char *pattern, uint8_t ignore_case) {
mz_zip_reader *reader = (mz_zip_reader *)handle;
reader->pattern = pattern;
if(!reader) /* pattern can be NULL */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space after if

mz_zip_rw.c Outdated
free(reader->pattern);
reader->pattern = NULL;
if(pattern)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

brace on prev line

mz_zip_rw.c Outdated
{
int32_t pattern_size = (int32_t)strlen(pattern);
reader->pattern = (char *)calloc(pattern_size + 1, sizeof(char));
if(!reader->pattern)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space after if.

@nmoinvaz nmoinvaz added the feature request Request for a new feature label Apr 15, 2025
@@ -230,6 +230,11 @@ int32_t mz_zip_reader_close(void *handle) {
mz_stream_delete(&reader->mem_stream);
}

if (reader->pattern) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On line 915 you didn't put any if, so why putting one here? You can probably remove it from line 233.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I referred to the mz_zip.c code, which is the similar code in mz_zip_set_comment and mz_zip_close. But the if in line 233 seems unnecessary indeed, I could remove it later.

@nmoinvaz nmoinvaz enabled auto-merge (rebase) April 16, 2025 15:16
@nmoinvaz nmoinvaz disabled auto-merge April 16, 2025 15:16
@nmoinvaz nmoinvaz merged commit e090f46 into zlib-ng:develop Apr 16, 2025
25 of 28 checks passed
Coeur added a commit to Coeur/minizip that referenced this pull request May 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request for a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants