From 5d9f95fca1a1f899a88b829b37e7fe4c807ce7b6 Mon Sep 17 00:00:00 2001 From: Nathan Moinvaziri Date: Thu, 30 Aug 2018 16:22:25 -0700 Subject: [PATCH] Fixed code analysis warnings. --- mz_os.c | 2 +- mz_strm.c | 2 +- mz_strm_aes.c | 2 +- mz_strm_buf.c | 8 ++++---- mz_strm_split.c | 11 +++++++++++ mz_strm_win32.c | 4 ++++ mz_zip.c | 10 ++++++---- 7 files changed, 28 insertions(+), 11 deletions(-) diff --git a/mz_os.c b/mz_os.c index 673a02c..73f6d34 100644 --- a/mz_os.c +++ b/mz_os.c @@ -329,7 +329,7 @@ int32_t mz_file_get_crc(const char *path, uint32_t *result_crc) void *crc32_stream = NULL; int32_t read = 0; int32_t err = MZ_OK; - uint8_t buf[INT16_MAX]; + uint8_t buf[16384]; mz_stream_os_create(&stream); diff --git a/mz_strm.c b/mz_strm.c index fbff428..e4a7abd 100644 --- a/mz_strm.c +++ b/mz_strm.c @@ -171,7 +171,7 @@ int32_t mz_stream_write_chars(void *stream, const char *value, uint8_t null_term int32_t mz_stream_copy(void *target, void *source, int32_t len) { - uint8_t buf[INT16_MAX]; + uint8_t buf[16384]; int32_t bytes_to_copy = 0; int32_t read = 0; int32_t written = 0; diff --git a/mz_strm_aes.c b/mz_strm_aes.c index dc2ce6e..ec46804 100644 --- a/mz_strm_aes.c +++ b/mz_strm_aes.c @@ -320,7 +320,7 @@ int32_t mz_stream_aes_get_prop_int64(void *stream, int32_t prop, int64_t *value) *value = aes->max_total_in; break; case MZ_STREAM_PROP_HEADER_SIZE: - *value = MZ_AES_SALT_LENGTH(aes->encryption_mode) + MZ_AES_PW_VERIFY_SIZE; + *value = MZ_AES_SALT_LENGTH((int64_t)aes->encryption_mode) + MZ_AES_PW_VERIFY_SIZE; break; case MZ_STREAM_PROP_FOOTER_SIZE: *value = MZ_AES_AUTHCODE_SIZE; diff --git a/mz_strm_buf.c b/mz_strm_buf.c index 9d581d7..26b60e8 100644 --- a/mz_strm_buf.c +++ b/mz_strm_buf.c @@ -264,7 +264,7 @@ int64_t mz_stream_buffered_tell(void *stream) buffered->position, buffered->readbuf_pos, buffered->writebuf_pos, errno); if (buffered->readbuf_len > 0) - position -= (buffered->readbuf_len - buffered->readbuf_pos); + position -= ((int64_t)buffered->readbuf_len - buffered->readbuf_pos); if (buffered->writebuf_len > 0) position += buffered->writebuf_pos; return position; @@ -307,17 +307,17 @@ int32_t mz_stream_buffered_seek(void *stream, int64_t offset, int32_t origin) if (buffered->readbuf_len > 0) { - if (offset <= (buffered->readbuf_len - buffered->readbuf_pos)) + if (offset <= ((int64_t)buffered->readbuf_len - buffered->readbuf_pos)) { buffered->readbuf_pos += (uint32_t)offset; return MZ_OK; } - offset -= (buffered->readbuf_len - buffered->readbuf_pos); + offset -= ((int64_t)buffered->readbuf_len - buffered->readbuf_pos); buffered->position += offset; } if (buffered->writebuf_len > 0) { - if (offset <= (buffered->writebuf_len - buffered->writebuf_pos)) + if (offset <= ((int64_t)buffered->writebuf_len - buffered->writebuf_pos)) { buffered->writebuf_pos += (uint32_t)offset; return MZ_OK; diff --git a/mz_strm_split.c b/mz_strm_split.c index ce22521..56b4e7b 100644 --- a/mz_strm_split.c +++ b/mz_strm_split.c @@ -182,10 +182,21 @@ int32_t mz_stream_split_open(void *stream, const char *path, int32_t mode) split->path_cd_size = (int32_t)strlen(path) + 1; split->path_cd = (char *)MZ_ALLOC(split->path_cd_size); + + if (split->path_cd == NULL) + return MZ_MEM_ERROR; + strncpy(split->path_cd, path, split->path_cd_size); split->path_disk_size = (int32_t)strlen(path) + 10; split->path_disk = (char *)MZ_ALLOC(split->path_disk_size); + + if (split->path_disk == NULL) + { + MZ_FREE(split->path_cd); + return MZ_MEM_ERROR; + } + strncpy(split->path_disk, path, split->path_disk_size); if (mode & MZ_OPEN_MODE_WRITE) diff --git a/mz_strm_win32.c b/mz_strm_win32.c index 7a62782..69ee94a 100644 --- a/mz_strm_win32.c +++ b/mz_strm_win32.c @@ -102,6 +102,10 @@ int32_t mz_stream_win32_open(void *stream, const char *path, int32_t mode) path_wide_size = MultiByteToWideChar(CP_UTF8, 0, path, -1, NULL, 0); path_wide = (wchar_t *)MZ_ALLOC((path_wide_size + 1) * sizeof(wchar_t)); + + if (path_wide == NULL) + return MZ_MEM_ERROR; + memset(path_wide, 0, sizeof(wchar_t) * (path_wide_size + 1)); MultiByteToWideChar(CP_UTF8, 0, path, -1, path_wide, path_wide_size); diff --git a/mz_zip.c b/mz_zip.c index 19858a5..a61ba1d 100644 --- a/mz_zip.c +++ b/mz_zip.c @@ -642,6 +642,8 @@ int32_t mz_zip_set_comment(void *handle, const char *comment) MZ_FREE(zip->comment); comment_size = (uint16_t)(strlen(comment) + 1); zip->comment = (char *)MZ_ALLOC(comment_size); + if (zip->comment == NULL) + return MZ_MEM_ERROR; strncpy(zip->comment, comment, comment_size); return MZ_OK; } @@ -761,7 +763,7 @@ static int32_t mz_zip_entry_read_header(void *stream, uint8_t local, mz_zip_file } } - max_seek = file_info->filename_size + file_info->extrafield_size + file_info->comment_size + 3; + max_seek = (int64_t)file_info->filename_size + file_info->extrafield_size + file_info->comment_size + 3; if (err == MZ_OK) err = mz_stream_seek(file_info_stream, max_seek, MZ_SEEK_SET); if (err == MZ_OK) @@ -775,7 +777,7 @@ static int32_t mz_zip_entry_read_header(void *stream, uint8_t local, mz_zip_file if (err == MZ_OK) err = mz_stream_write_uint8(file_info_stream, 0); - seek += file_info->filename_size + 1; + seek += (int64_t)file_info->filename_size + 1; } if ((err == MZ_OK) && (file_info->extrafield_size > 0)) @@ -790,7 +792,7 @@ static int32_t mz_zip_entry_read_header(void *stream, uint8_t local, mz_zip_file if (err == MZ_OK) err = mz_stream_seek(file_info_stream, seek, MZ_SEEK_SET); - seek += file_info->extrafield_size + 1; + seek += (int64_t)file_info->extrafield_size + 1; while ((err == MZ_OK) && (extra_pos < file_info->extrafield_size)) { @@ -1782,7 +1784,7 @@ int32_t mz_zip_goto_next_entry(void *handle) if (zip == NULL) return MZ_PARAM_ERROR; - zip->cd_current_pos += MZ_ZIP_SIZE_CD_ITEM + zip->file_info.filename_size + + zip->cd_current_pos += (uint64_t)MZ_ZIP_SIZE_CD_ITEM + zip->file_info.filename_size + zip->file_info.extrafield_size + zip->file_info.comment_size; return mz_zip_goto_next_entry_int(handle);