Skip to content

Commit

Permalink
Fix potential bug
Browse files Browse the repository at this point in the history
  • Loading branch information
fpseverino committed Aug 26, 2024
1 parent 97be6e0 commit 69f0bba
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Sources/Zip/Zip.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ public class Zip {
}

var writeBytes: UInt64 = 0
while let filePointer = fopen(fullPath, "wb") {
defer { fclose(filePointer) }
var filePointer: UnsafeMutablePointer<FILE>?
filePointer = fopen(fullPath, "wb")
while let filePointer {
let readBytes = unzReadCurrentFile(zip, &buffer, bufferSize)
if readBytes > 0 {
guard fwrite(buffer, Int(readBytes), 1, filePointer) == 1 else {
Expand All @@ -149,6 +150,8 @@ public class Zip {
} else { break }
}

if let filePointer { fclose(filePointer) }

crc_ret = unzCloseCurrentFile(zip)
if crc_ret == UNZ_CRCERROR {
throw ZipError.unzipFail
Expand Down Expand Up @@ -282,7 +285,7 @@ public class Zip {
}
if let password, let fileName {
zipOpenNewFileInZip3(zip, fileName, &zipInfo, nil, 0, nil, 0, nil, Z_DEFLATED, compression.minizipCompression, 0, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, password, 0)
} else if let fileName = fileName {
} else if let fileName {
zipOpenNewFileInZip3(zip, fileName, &zipInfo, nil, 0, nil, 0, nil, Z_DEFLATED, compression.minizipCompression, 0, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, nil, 0)
} else {
throw ZipError.zipFail
Expand Down

0 comments on commit 69f0bba

Please sign in to comment.