X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=ShellPkg%2FLibrary%2FUefiShellDebug1CommandsLib%2FCompress.c;h=cde2c54f1b45edd5ebdfb2de952a544bd56f9c21;hp=afe3ec08582a489630c49bfbeb5aa7f9f8e19533;hb=3dbf922901c0fea2c6dc1c3fe9fa1911af889fbf;hpb=16751bb43d985132923173773a64595c15d8c290 diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Compress.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Compress.c index afe3ec0858..cde2c54f1b 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Compress.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Compress.c @@ -7,7 +7,7 @@ This sequence is further divided into Blocks and Huffman codings are applied to each Block. - Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.
+ Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -17,11 +17,13 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ - +#include #include #include #include -#include +#include + +#include "Compress.h" // // Macro Definitions @@ -67,7 +69,6 @@ typedef INT16 NODE; @param[in] Data The dword to put. **/ VOID -EFIAPI PutDword( IN UINT32 Data ); @@ -127,7 +128,6 @@ INT32 mHuffmanDepth = 0; **/ VOID -EFIAPI MakeCrcTable ( VOID ) @@ -158,7 +158,6 @@ MakeCrcTable ( @param[in] Data The dword to put. **/ VOID -EFIAPI PutDword ( IN UINT32 Data ) @@ -187,7 +186,6 @@ PutDword ( @retval EFI_OUT_OF_RESOURCES A memory allocation failed. **/ EFI_STATUS -EFIAPI AllocateMemory ( VOID ) @@ -221,7 +219,6 @@ AllocateMemory ( **/ VOID -EFIAPI FreeMemory ( VOID ) @@ -237,11 +234,9 @@ FreeMemory ( } /** - Initialize String Info Log data structures - + Initialize String Info Log data structures. **/ VOID -EFIAPI InitSlide ( VOID ) @@ -273,7 +268,6 @@ InitSlide ( **/ NODE -EFIAPI Child ( IN NODE LoopVar6, IN UINT8 LoopVar5 @@ -298,7 +292,6 @@ Child ( @param[in] LoopVar4 The child node. **/ VOID -EFIAPI MakeChild ( IN NODE LoopVar6, IN UINT8 LoopVar5, @@ -325,7 +318,6 @@ MakeChild ( @param[in] Old The node to split. **/ VOID -EFIAPI Split ( IN NODE Old ) @@ -355,7 +347,6 @@ Split ( **/ VOID -EFIAPI InsertNode ( VOID ) @@ -484,7 +475,6 @@ InsertNode ( **/ VOID -EFIAPI DeleteNode ( VOID ) @@ -579,7 +569,6 @@ DeleteNode ( @return The number of bytes actually read. **/ INT32 -EFIAPI FreadCrc ( OUT UINT8 *LoopVar7, IN INT32 LoopVar8 @@ -608,9 +597,10 @@ FreadCrc ( Advance the current position (read in new data if needed). Delete outdated string info. Find a match string for current position. + @retval TRUE The operation was successful. + @retval FALSE The operation failed due to insufficient memory. **/ -VOID -EFIAPI +BOOLEAN GetNextMatch ( VOID ) @@ -622,6 +612,9 @@ GetNextMatch ( mPos++; if (mPos == WNDSIZ * 2) { Temp = AllocateZeroPool (WNDSIZ + MAXMATCH); + if (Temp == NULL) { + return (FALSE); + } CopyMem (Temp, &mText[WNDSIZ], WNDSIZ + MAXMATCH); CopyMem (&mText[0], Temp, WNDSIZ + MAXMATCH); FreePool (Temp); @@ -632,6 +625,8 @@ GetNextMatch ( DeleteNode (); InsertNode (); + + return (TRUE); } /** @@ -640,7 +635,6 @@ GetNextMatch ( @param[in] LoopVar1 The index of the item to move. **/ VOID -EFIAPI DownHeap ( IN INT32 i ) @@ -677,7 +671,6 @@ DownHeap ( @param[in] LoopVar1 The top node. **/ VOID -EFIAPI CountLen ( IN INT32 LoopVar1 ) @@ -698,7 +691,6 @@ CountLen ( @param[in] Root The root of the tree. **/ VOID -EFIAPI MakeLen ( IN INT32 Root ) @@ -754,7 +746,6 @@ MakeLen ( @param[out] Code The stores codes for each symbol. **/ VOID -EFIAPI MakeCode ( IN INT32 LoopVar8, IN UINT8 Len[ ], @@ -785,7 +776,6 @@ MakeCode ( @return The root of the Huffman tree. **/ INT32 -EFIAPI MakeTree ( IN INT32 NParm, IN UINT16 FreqParm[ ], @@ -869,7 +859,6 @@ MakeTree ( @param[in] x The data. **/ VOID -EFIAPI PutBits ( IN INT32 LoopVar8, IN UINT32 x @@ -908,7 +897,6 @@ PutBits ( @param[in] LoopVar5 The number to encode. **/ VOID -EFIAPI EncodeC ( IN INT32 LoopVar5 ) @@ -922,7 +910,6 @@ EncodeC ( @param[in] LoopVar7 The number to encode. **/ VOID -EFIAPI EncodeP ( IN UINT32 LoopVar7 ) @@ -949,7 +936,6 @@ EncodeP ( **/ VOID -EFIAPI CountTFreq ( VOID ) @@ -1007,7 +993,6 @@ CountTFreq ( **/ VOID -EFIAPI WritePTLen ( IN INT32 LoopVar8, IN INT32 nbit, @@ -1043,11 +1028,9 @@ WritePTLen ( } /** - Outputs the code length array for Char&Length Set - + Outputs the code length array for Char&Length Set. **/ VOID -EFIAPI WriteCLen ( VOID ) @@ -1103,7 +1086,6 @@ WriteCLen ( **/ VOID -EFIAPI SendBlock ( VOID ) @@ -1177,7 +1159,6 @@ SendBlock ( **/ VOID -EFIAPI HufEncodeStart ( VOID ) @@ -1199,7 +1180,6 @@ HufEncodeStart ( @param[in] LoopVar7 The 'Position' field of a Pointer. **/ VOID -EFIAPI CompressOutput ( IN UINT32 LoopVar5, IN UINT32 LoopVar7 @@ -1237,7 +1217,6 @@ CompressOutput ( **/ VOID -EFIAPI HufEncodeEnd ( VOID ) @@ -1257,7 +1236,6 @@ HufEncodeEnd ( @retval EFI_OUT_0F_RESOURCES Not enough memory for compression process. **/ EFI_STATUS -EFIAPI Encode ( VOID ) @@ -1288,7 +1266,9 @@ Encode ( while (mRemainder > 0) { LastMatchLen = mMatchLen; LastMatchPos = mMatchPos; - GetNextMatch (); + if (!GetNextMatch ()) { + Status = EFI_OUT_OF_RESOURCES; + } if (mMatchLen > mRemainder) { mMatchLen = mRemainder; } @@ -1308,7 +1288,9 @@ Encode ( (mPos - LastMatchPos - 2) & (WNDSIZ - 1)); LastMatchLen--; while (LastMatchLen > 0) { - GetNextMatch (); + if (!GetNextMatch ()) { + Status = EFI_OUT_OF_RESOURCES; + } LastMatchLen--; } @@ -1320,28 +1302,27 @@ Encode ( HufEncodeEnd (); FreeMemory (); - return EFI_SUCCESS; + return (Status); } /** The compression routine. - @param[in] SrcBuffer The buffer containing the source data. - @param[in] SrcSize The number of bytes in SrcBuffer. - @param[in] DstBuffer The buffer to put the compressed image in. - @param[in,out] DstSize On input the size (in bytes) of DstBuffer, on - return the number of bytes placed in DstBuffer. + @param[in] SrcBuffer The buffer containing the source data. + @param[in] SrcSize Number of bytes in SrcBuffer. + @param[in] DstBuffer The buffer to put the compressed image in. + @param[in, out] DstSize On input the size (in bytes) of DstBuffer, on + return the number of bytes placed in DstBuffer. @retval EFI_SUCCESS The compression was sucessful. @retval EFI_BUFFER_TOO_SMALL The buffer was too small. DstSize is required. **/ EFI_STATUS -EFIAPI Compress ( - IN VOID *SrcBuffer, - IN UINT64 SrcSize, - IN VOID *DstBuffer, - IN OUT UINT64 *DstSize + IN VOID *SrcBuffer, + IN UINT64 SrcSize, + IN VOID *DstBuffer, + IN OUT UINT64 *DstSize ) { EFI_STATUS Status;