From c14eccefaf0ba0286d2e9f3ae7b8dd1f3e055a27 Mon Sep 17 00:00:00 2001 From: Jonas Karlsson Date: Wed, 9 Mar 2022 22:19:10 +0100 Subject: [PATCH 1/2] Fix 'i >= 0' always true bug If 'disk_filename' does not contain a dot (.) then 'i' would overflow. Making 'i' an int makes sure the for loop works as intended. --- code/Common/ZipArchiveIOSystem.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/Common/ZipArchiveIOSystem.cpp b/code/Common/ZipArchiveIOSystem.cpp index c322b140f..ba90ae9b3 100644 --- a/code/Common/ZipArchiveIOSystem.cpp +++ b/code/Common/ZipArchiveIOSystem.cpp @@ -122,7 +122,7 @@ voidpf IOSystem2Unzip::open(voidpf opaque, const char *filename, int mode) { voidpf IOSystem2Unzip::opendisk(voidpf opaque, voidpf stream, uint32_t number_disk, int mode) { ZipFile *io_stream = (ZipFile *)stream; voidpf ret = NULL; - size_t i; + int i; char *disk_filename = (char*)malloc(io_stream->m_Filename.length() + 1); strncpy(disk_filename, io_stream->m_Filename.c_str(), io_stream->m_Filename.length() + 1); @@ -130,7 +130,7 @@ voidpf IOSystem2Unzip::opendisk(voidpf opaque, voidpf stream, uint32_t number_di { if (disk_filename[i] != '.') continue; - snprintf(&disk_filename[i], io_stream->m_Filename.length() - i, ".z%02u", number_disk + 1); + snprintf(&disk_filename[i], io_stream->m_Filename.length() - size_t(i), ".z%02u", number_disk + 1); break; } From 47f004517fca061e89896f2244be32fe6a506eb9 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 10 Mar 2022 10:33:29 +0100 Subject: [PATCH 2/2] Add missing cast. --- code/Common/ZipArchiveIOSystem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/Common/ZipArchiveIOSystem.cpp b/code/Common/ZipArchiveIOSystem.cpp index ba90ae9b3..e0c9883d2 100644 --- a/code/Common/ZipArchiveIOSystem.cpp +++ b/code/Common/ZipArchiveIOSystem.cpp @@ -126,7 +126,7 @@ voidpf IOSystem2Unzip::opendisk(voidpf opaque, voidpf stream, uint32_t number_di char *disk_filename = (char*)malloc(io_stream->m_Filename.length() + 1); strncpy(disk_filename, io_stream->m_Filename.c_str(), io_stream->m_Filename.length() + 1); - for (i = io_stream->m_Filename.length() - 1; i >= 0; i -= 1) + for (i = (int)io_stream->m_Filename.length() - 1; i >= 0; i -= 1) { if (disk_filename[i] != '.') continue;