aboutsummaryrefslogtreecommitdiff
path: root/dep/CascLib/src/CascDecompress.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'dep/CascLib/src/CascDecompress.cpp')
-rw-r--r--dep/CascLib/src/CascDecompress.cpp22
1 files changed, 16 insertions, 6 deletions
diff --git a/dep/CascLib/src/CascDecompress.cpp b/dep/CascLib/src/CascDecompress.cpp
index e60adb8f97b..3262c59ddf7 100644
--- a/dep/CascLib/src/CascDecompress.cpp
+++ b/dep/CascLib/src/CascDecompress.cpp
@@ -18,29 +18,39 @@
int CascDecompress(LPBYTE pbOutBuffer, PDWORD pcbOutBuffer, LPBYTE pbInBuffer, DWORD cbInBuffer)
{
z_stream z; // Stream information for zlib
+ uInt cbOutBuffer = *pcbOutBuffer;
int nResult;
+ int nError = ERROR_FILE_CORRUPT;
// Fill the stream structure for zlib
z.next_in = pbInBuffer;
z.avail_in = cbInBuffer;
z.total_in = cbInBuffer;
z.next_out = pbOutBuffer;
- z.avail_out = *pcbOutBuffer;
+ z.avail_out = cbOutBuffer;
z.total_out = 0;
z.zalloc = NULL;
z.zfree = NULL;
+ // Reset the total number of output bytes
+ cbOutBuffer = 0;
+
// Initialize the decompression structure
if((nResult = inflateInit(&z)) == Z_OK)
{
// Call zlib to decompress the data
nResult = inflate(&z, Z_NO_FLUSH);
- inflateEnd(&z);
+ if (nResult == Z_OK || nResult == Z_STREAM_END)
+ {
+ // Give the size of the uncompressed data
+ cbOutBuffer = z.total_out;
+ nError = ERROR_SUCCESS;
+ }
- // Give the size of the uncompressed data
- *pcbOutBuffer = z.total_out;
+ inflateEnd(&z);
}
- // Return an error code
- return (nResult == Z_OK || nResult == Z_STREAM_END) ? ERROR_SUCCESS : ERROR_FILE_CORRUPT;
+ // Give the caller the number of bytes needed
+ pcbOutBuffer[0] = cbOutBuffer;
+ return nError;
}