diff options
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;  }  /******************************************************************************/  | 
