Fix and reindent LZMA

This commit is contained in:
vit9696 2018-05-08 18:16:28 +03:00
parent d87cbe3210
commit bbdfe28449
4 changed files with 105 additions and 103 deletions

View File

@ -58,13 +58,13 @@ SetEncodedSizeOfBuf(
}
}
INT32
USTATUS
EFIAPI
LzmaCompress (
CONST UINT8 *Source,
UINTN SourceSize,
UINT32 SourceSize,
UINT8 *Destination,
UINTN *DestinationSize
UINT32 *DestinationSize
)
{
SRes LzmaResult;
@ -72,14 +72,14 @@ LzmaCompress(
SizeT propsSize = LZMA_PROPS_SIZE;
SizeT destLen = SourceSize + SourceSize / 3 + 128;
if (*DestinationSize < destLen)
if (*DestinationSize < (UINT32)destLen)
{
*DestinationSize = (UINTN)destLen;
*DestinationSize = (UINT32)destLen;
return EFI_BUFFER_TOO_SMALL;
}
LzmaEncProps_Init(&props);
// TOOD: need to detect this instead of hardcoding
// TODO: need to detect this instead of hardcoding
props.dictSize = LZMA_DICTIONARY_SIZE;
props.level = 9;
props.fb = 273;
@ -88,7 +88,7 @@ LzmaCompress(
(Byte*)((UINT8*)Destination + LZMA_HEADER_SIZE),
&destLen,
Source,
SourceSize,
(SizeT)SourceSize,
&props,
(UINT8*)Destination,
&propsSize,
@ -97,7 +97,7 @@ LzmaCompress(
&SzAllocForLzma,
&SzAllocForLzma);
*DestinationSize = destLen + LZMA_HEADER_SIZE;
*DestinationSize = (UINT32)(destLen + LZMA_HEADER_SIZE);
SetEncodedSizeOfBuf(SourceSize, Destination);

View File

@ -24,13 +24,13 @@ extern "C" {
#define LZMA_DICTIONARY_SIZE 0x800000
#define _LZMA_SIZE_OPT
INT32
USTATUS
EFIAPI
LzmaCompress (
const UINT8 *Source,
UINTN SourceSize,
UINT32 SourceSize,
UINT8 *Destination,
UINTN *DestinationSize
UINT32 *DestinationSize
);
#ifdef __cplusplus

View File

@ -85,19 +85,28 @@ DestinationSize and the size of the scratch
buffer was returned ScratchSize.
*/
INT32
USTATUS
EFIAPI
LzmaGetInfo (
CONST VOID *Source,
UINTN SourceSize,
UINTN *DestinationSize
UINT32 SourceSize,
UINT32 *DestinationSize
)
{
ASSERT(SourceSize >= LZMA_HEADER_SIZE); (void)SourceSize;
UINT64 DecodedSize;
ASSERT(SourceSize >= LZMA_HEADER_SIZE);
(void)SourceSize;
*DestinationSize = (UINTN)GetDecodedSizeOfBuf((UINT8*)Source);
DecodedSize = GetDecodedSizeOfBuf((UINT8*)Source);
if (DecodedSize <= UINT32_MAX) {
*DestinationSize = (UINT32)DecodedSize;
return U_SUCCESS;
}
else {
return U_INVALID_PARAMETER;
}
}
/*
Decompresses a Lzma compressed source buffer.
@ -118,11 +127,11 @@ the uncompressed buffer is returned Destination.
The source buffer specified by Source is corrupted
(not a valid compressed format).
*/
INT32
USTATUS
EFIAPI
LzmaDecompress (
CONST VOID *Source,
UINTN SourceSize,
UINT32 SourceSize,
VOID *Destination
)
{

View File

@ -23,13 +23,6 @@ extern "C" {
#define LZMA_HEADER_SIZE (LZMA_PROPS_SIZE + 8)
UINT64
EFIAPI
LShiftU64(
UINT64 Operand,
UINT32 Count
);
/*
Given a Lzma compressed source buffer, this function retrieves the size of
the uncompressed buffer and the size of the scratch buffer required
@ -57,10 +50,10 @@ extern "C" {
buffer was returned ScratchSize.
*/
INT32
USTATUS
EFIAPI
LzmaGetInfo (
const VOID *Source,
CONST VOID *Source,
UINT32 SourceSize,
UINT32 *DestinationSize
);
@ -84,10 +77,10 @@ extern "C" {
The source buffer specified by Source is corrupted
(not a valid compressed format).
*/
INT32
USTATUS
EFIAPI
LzmaDecompress (
const VOID *Source,
CONST VOID *Source,
UINT32 SourceSize,
VOID *Destination
);