diff options
author | Ladislav Zezula <ladislav.zezula@avast.com> | 2021-07-06 22:47:39 +0200 |
---|---|---|
committer | Ladislav Zezula <ladislav.zezula@avast.com> | 2021-07-06 22:47:39 +0200 |
commit | c5fb5c7dfa40ae1304ac2ebf1431a9d6a2ba4d13 (patch) | |
tree | 5abcbd3d8eb2a11ff2aaa2011eaace0a13e4c2c9 /src/SCompression.cpp | |
parent | 48c3ae62151efd49592cf75359ecf23cdab9b69d (diff) |
Beautifying
Diffstat (limited to 'src/SCompression.cpp')
-rw-r--r-- | src/SCompression.cpp | 48 |
1 files changed, 22 insertions, 26 deletions
diff --git a/src/SCompression.cpp b/src/SCompression.cpp index ae7082b..1d0f679 100644 --- a/src/SCompression.cpp +++ b/src/SCompression.cpp @@ -175,7 +175,7 @@ int Decompress_ZLIB(void * pvOutBuffer, int * pcbOutBuffer, void * pvInBuffer, i *pcbOutBuffer = z.total_out; inflateEnd(&z); } - + return (nResult >= Z_OK); } @@ -279,33 +279,29 @@ static void Compress_PKLIB(void * pvOutBuffer, int * pcbOutBuffer, void * pvInBu static int Decompress_PKLIB(void * pvOutBuffer, int * pcbOutBuffer, void * pvInBuffer, int cbInBuffer) { TDataInfo Info; // Data information - char * work_buf = STORM_ALLOC(char, EXP_BUFFER_SIZE);// Pklib's work buffer - - // Handle no-memory condition - if(work_buf == NULL) - return 0; - - // Fill data information structure - memset(work_buf, 0, EXP_BUFFER_SIZE); - Info.pbInBuff = (unsigned char *)pvInBuffer; - Info.pbInBuffEnd = (unsigned char *)pvInBuffer + cbInBuffer; - Info.pbOutBuff = (unsigned char *)pvOutBuffer; - Info.pbOutBuffEnd = (unsigned char *)pvOutBuffer + *pcbOutBuffer; - - // Do the decompression - explode(ReadInputData, WriteOutputData, work_buf, &Info); - - // If PKLIB is unable to decompress the data, return 0; - if(Info.pbOutBuff == pvOutBuffer) - { + char * work_buf; + int nResult = 0; + + // Allocate Pklib's work buffer + if((work_buf = STORM_ALLOC(char, EXP_BUFFER_SIZE)) != NULL) + { + // Fill data information structure + memset(work_buf, 0, EXP_BUFFER_SIZE); + Info.pbInBuff = (unsigned char *)pvInBuffer; + Info.pbInBuffEnd = (unsigned char *)pvInBuffer + cbInBuffer; + Info.pbOutBuff = (unsigned char *)pvOutBuffer; + Info.pbOutBuffEnd = (unsigned char *)pvOutBuffer + *pcbOutBuffer; + + // Do the decompression + if(explode(ReadInputData, WriteOutputData, work_buf, &Info) == CMP_NO_ERROR) + nResult = 1; + + // Give away the number of decompressed bytes + *pcbOutBuffer = (int)(Info.pbOutBuff - (unsigned char *)pvOutBuffer); STORM_FREE(work_buf); - return 0; - } + } - // Give away the number of decompressed bytes - *pcbOutBuffer = (int)(Info.pbOutBuff - (unsigned char *)pvOutBuffer); - STORM_FREE(work_buf); - return 1; + return nResult; } /******************************************************************************/ |