-
-
Notifications
You must be signed in to change notification settings - Fork 465
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
Conversation
mz_zip_rw.c
Outdated
return; | ||
free(reader->pattern); | ||
reader->pattern = NULL; | ||
if(pattern) |
There was a problem hiding this comment.
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 */ |
There was a problem hiding this comment.
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) | ||
{ |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space after if.
@@ -230,6 +230,11 @@ int32_t mz_zip_reader_close(void *handle) { | |||
mz_stream_delete(&reader->mem_stream); | |||
} | |||
|
|||
if (reader->pattern) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Since
pattern
should be used along with the usage of functions likemz_zip_reader_goto_next_entry
, and one could put a dynamically-assignedpattern
in another function, which makes it difficult to free the original string, there's need to make thepattern
inmz_zip_reader
dynamically assigned, and the old string can be freed immediately.