X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=ShellPkg%2FLibrary%2FUefiShellDebug1CommandsLib%2FCompress.c;h=736d2a35b3ac595de1232f1e533e60ec3d2ff256;hp=afe3ec08582a489630c49bfbeb5aa7f9f8e19533;hb=7162fdb037fb9385f6bd7d0dc55d54029b810de2;hpb=16751bb43d985132923173773a64595c15d8c290
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Compress.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Compress.c
index afe3ec0858..736d2a35b3 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,11 @@
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
-
+#include
#include
#include
#include
-#include
+#include
//
// Macro Definitions
@@ -67,7 +67,6 @@ typedef INT16 NODE;
@param[in] Data The dword to put.
**/
VOID
-EFIAPI
PutDword(
IN UINT32 Data
);
@@ -127,7 +126,6 @@ INT32 mHuffmanDepth = 0;
**/
VOID
-EFIAPI
MakeCrcTable (
VOID
)
@@ -158,7 +156,6 @@ MakeCrcTable (
@param[in] Data The dword to put.
**/
VOID
-EFIAPI
PutDword (
IN UINT32 Data
)
@@ -187,7 +184,6 @@ PutDword (
@retval EFI_OUT_OF_RESOURCES A memory allocation failed.
**/
EFI_STATUS
-EFIAPI
AllocateMemory (
VOID
)
@@ -221,7 +217,6 @@ AllocateMemory (
**/
VOID
-EFIAPI
FreeMemory (
VOID
)
@@ -237,11 +232,9 @@ FreeMemory (
}
/**
- Initialize String Info Log data structures
-
+ Initialize String Info Log data structures.
**/
VOID
-EFIAPI
InitSlide (
VOID
)
@@ -273,7 +266,6 @@ InitSlide (
**/
NODE
-EFIAPI
Child (
IN NODE LoopVar6,
IN UINT8 LoopVar5
@@ -298,7 +290,6 @@ Child (
@param[in] LoopVar4 The child node.
**/
VOID
-EFIAPI
MakeChild (
IN NODE LoopVar6,
IN UINT8 LoopVar5,
@@ -325,7 +316,6 @@ MakeChild (
@param[in] Old The node to split.
**/
VOID
-EFIAPI
Split (
IN NODE Old
)
@@ -355,7 +345,6 @@ Split (
**/
VOID
-EFIAPI
InsertNode (
VOID
)
@@ -484,7 +473,6 @@ InsertNode (
**/
VOID
-EFIAPI
DeleteNode (
VOID
)
@@ -579,7 +567,6 @@ DeleteNode (
@return The number of bytes actually read.
**/
INT32
-EFIAPI
FreadCrc (
OUT UINT8 *LoopVar7,
IN INT32 LoopVar8
@@ -608,9 +595,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 +610,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 +623,8 @@ GetNextMatch (
DeleteNode ();
InsertNode ();
+
+ return (TRUE);
}
/**
@@ -640,7 +633,6 @@ GetNextMatch (
@param[in] LoopVar1 The index of the item to move.
**/
VOID
-EFIAPI
DownHeap (
IN INT32 i
)
@@ -677,7 +669,6 @@ DownHeap (
@param[in] LoopVar1 The top node.
**/
VOID
-EFIAPI
CountLen (
IN INT32 LoopVar1
)
@@ -698,7 +689,6 @@ CountLen (
@param[in] Root The root of the tree.
**/
VOID
-EFIAPI
MakeLen (
IN INT32 Root
)
@@ -754,7 +744,6 @@ MakeLen (
@param[out] Code The stores codes for each symbol.
**/
VOID
-EFIAPI
MakeCode (
IN INT32 LoopVar8,
IN UINT8 Len[ ],
@@ -785,7 +774,6 @@ MakeCode (
@return The root of the Huffman tree.
**/
INT32
-EFIAPI
MakeTree (
IN INT32 NParm,
IN UINT16 FreqParm[ ],
@@ -869,7 +857,6 @@ MakeTree (
@param[in] x The data.
**/
VOID
-EFIAPI
PutBits (
IN INT32 LoopVar8,
IN UINT32 x
@@ -908,7 +895,6 @@ PutBits (
@param[in] LoopVar5 The number to encode.
**/
VOID
-EFIAPI
EncodeC (
IN INT32 LoopVar5
)
@@ -922,7 +908,6 @@ EncodeC (
@param[in] LoopVar7 The number to encode.
**/
VOID
-EFIAPI
EncodeP (
IN UINT32 LoopVar7
)
@@ -949,7 +934,6 @@ EncodeP (
**/
VOID
-EFIAPI
CountTFreq (
VOID
)
@@ -1007,7 +991,6 @@ CountTFreq (
**/
VOID
-EFIAPI
WritePTLen (
IN INT32 LoopVar8,
IN INT32 nbit,
@@ -1043,11 +1026,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 +1084,6 @@ WriteCLen (
**/
VOID
-EFIAPI
SendBlock (
VOID
)
@@ -1177,7 +1157,6 @@ SendBlock (
**/
VOID
-EFIAPI
HufEncodeStart (
VOID
)
@@ -1199,7 +1178,6 @@ HufEncodeStart (
@param[in] LoopVar7 The 'Position' field of a Pointer.
**/
VOID
-EFIAPI
CompressOutput (
IN UINT32 LoopVar5,
IN UINT32 LoopVar7
@@ -1237,7 +1215,6 @@ CompressOutput (
**/
VOID
-EFIAPI
HufEncodeEnd (
VOID
)
@@ -1257,7 +1234,6 @@ HufEncodeEnd (
@retval EFI_OUT_0F_RESOURCES Not enough memory for compression process.
**/
EFI_STATUS
-EFIAPI
Encode (
VOID
)
@@ -1288,7 +1264,9 @@ Encode (
while (mRemainder > 0) {
LastMatchLen = mMatchLen;
LastMatchPos = mMatchPos;
- GetNextMatch ();
+ if (!GetNextMatch ()) {
+ Status = EFI_OUT_OF_RESOURCES;
+ }
if (mMatchLen > mRemainder) {
mMatchLen = mRemainder;
}
@@ -1308,7 +1286,9 @@ Encode (
(mPos - LastMatchPos - 2) & (WNDSIZ - 1));
LastMatchLen--;
while (LastMatchLen > 0) {
- GetNextMatch ();
+ if (!GetNextMatch ()) {
+ Status = EFI_OUT_OF_RESOURCES;
+ }
LastMatchLen--;
}
@@ -1320,23 +1300,22 @@ 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
+ @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.
@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,