aboutsummaryrefslogtreecommitdiff
path: root/dep/CascLib/src/CascDecompress.cpp
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2019-06-06 16:48:21 +0200
committerShauren <shauren.trinity@gmail.com>2019-06-08 17:09:24 +0200
commitfc330fd8ff0115804d9c4b53a1f810c00dd63de9 (patch)
treecfa10998fed66779834bf0b7a9b8b799d33d91d4 /dep/CascLib/src/CascDecompress.cpp
parent82c7b6c5688495d90c4ee5995a4ff74039348296 (diff)
Dep/CascLib: Update to ladislav-zezula/CascLib@a1197edf0b3bd4d52c3f39be7fa7b44bb0b98012
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;
}