Browse Source

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.
Jonas Karlsson 3 years ago
parent
commit
c14eccefaf
1 changed files with 2 additions and 2 deletions
  1. 2 2
      code/Common/ZipArchiveIOSystem.cpp

+ 2 - 2
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;
     }