]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellDebug1CommandsLib/Compress.c
ShellPkg/Debug1CommandsLib: Fix bugs in func DisplaySysEventLogData
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / Compress.c
index 01321d1ed674d7451750afb0c0e1d3ceccc49085..4d9a6fb46729e82e726a1ad17d9f963f4e147156 100644 (file)
@@ -7,21 +7,17 @@
   This sequence is further divided into Blocks and Huffman codings\r
   are applied to each Block.\r
 \r
-  Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>\r
-  This program and the accompanying materials\r
-  are licensed and made available under the terms and conditions of the BSD License\r
-  which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
-\r
+#include <Uefi.h>\r
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/DebugLib.h>\r
-#include <ShellBase.h>\r
+#include <Library/ShellLib.h>\r
+\r
+#include "Compress.h"\r
 \r
 //\r
 // Macro Definitions\r
@@ -67,7 +63,6 @@ typedef INT16             NODE;
   @param[in] Data    The dword to put.\r
 **/\r
 VOID\r
-EFIAPI\r
 PutDword(\r
   IN UINT32 Data\r
   );\r
@@ -127,7 +122,6 @@ INT32         mHuffmanDepth = 0;
 \r
 **/\r
 VOID\r
-EFIAPI\r
 MakeCrcTable (\r
   VOID\r
   )\r
@@ -158,7 +152,6 @@ MakeCrcTable (
   @param[in] Data    The dword to put.\r
 **/\r
 VOID\r
-EFIAPI\r
 PutDword (\r
   IN UINT32 Data\r
   )\r
@@ -182,12 +175,11 @@ PutDword (
 \r
 /**\r
   Allocate memory spaces for data structures used in compression process.\r
-  \r
+\r
   @retval EFI_SUCCESS           Memory was allocated successfully.\r
   @retval EFI_OUT_OF_RESOURCES  A memory allocation failed.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 AllocateMemory (\r
   VOID\r
   )\r
@@ -221,7 +213,6 @@ AllocateMemory (
 \r
 **/\r
 VOID\r
-EFIAPI\r
 FreeMemory (\r
   VOID\r
   )\r
@@ -240,7 +231,6 @@ FreeMemory (
   Initialize String Info Log data structures.\r
 **/\r
 VOID\r
-EFIAPI\r
 InitSlide (\r
   VOID\r
   )\r
@@ -272,7 +262,6 @@ InitSlide (
 \r
 **/\r
 NODE\r
-EFIAPI\r
 Child (\r
   IN NODE   LoopVar6,\r
   IN UINT8  LoopVar5\r
@@ -297,7 +286,6 @@ Child (
   @param[in] LoopVar4       The child node.\r
 **/\r
 VOID\r
-EFIAPI\r
 MakeChild (\r
   IN NODE   LoopVar6,\r
   IN UINT8  LoopVar5,\r
@@ -324,7 +312,6 @@ MakeChild (
   @param[in] Old     The node to split.\r
 **/\r
 VOID\r
-EFIAPI\r
 Split (\r
   IN NODE Old\r
   )\r
@@ -354,7 +341,6 @@ Split (
 \r
 **/\r
 VOID\r
-EFIAPI\r
 InsertNode (\r
   VOID\r
   )\r
@@ -483,7 +469,6 @@ InsertNode (
 \r
 **/\r
 VOID\r
-EFIAPI\r
 DeleteNode (\r
   VOID\r
   )\r
@@ -578,7 +563,6 @@ DeleteNode (
   @return The number of bytes actually read.\r
 **/\r
 INT32\r
-EFIAPI\r
 FreadCrc (\r
   OUT UINT8 *LoopVar7,\r
   IN  INT32 LoopVar8\r
@@ -607,9 +591,10 @@ FreadCrc (
   Advance the current position (read in new data if needed).\r
   Delete outdated string info. Find a match string for current position.\r
 \r
+  @retval TRUE      The operation was successful.\r
+  @retval FALSE     The operation failed due to insufficient memory.\r
 **/\r
-VOID\r
-EFIAPI\r
+BOOLEAN\r
 GetNextMatch (\r
   VOID\r
   )\r
@@ -621,6 +606,9 @@ GetNextMatch (
   mPos++;\r
   if (mPos == WNDSIZ * 2) {\r
     Temp = AllocateZeroPool (WNDSIZ + MAXMATCH);\r
+    if (Temp == NULL) {\r
+      return (FALSE);\r
+    }\r
     CopyMem (Temp, &mText[WNDSIZ], WNDSIZ + MAXMATCH);\r
     CopyMem (&mText[0], Temp, WNDSIZ + MAXMATCH);\r
     FreePool (Temp);\r
@@ -631,6 +619,8 @@ GetNextMatch (
 \r
   DeleteNode ();\r
   InsertNode ();\r
+\r
+  return (TRUE);\r
 }\r
 \r
 /**\r
@@ -639,7 +629,6 @@ GetNextMatch (
   @param[in] LoopVar1    The index of the item to move.\r
 **/\r
 VOID\r
-EFIAPI\r
 DownHeap (\r
   IN INT32 i\r
   )\r
@@ -676,7 +665,6 @@ DownHeap (
   @param[in] LoopVar1      The top node.\r
 **/\r
 VOID\r
-EFIAPI\r
 CountLen (\r
   IN INT32 LoopVar1\r
   )\r
@@ -697,7 +685,6 @@ CountLen (
   @param[in] Root   The root of the tree.\r
 **/\r
 VOID\r
-EFIAPI\r
 MakeLen (\r
   IN INT32 Root\r
   )\r
@@ -747,13 +734,12 @@ MakeLen (
 \r
 /**\r
   Assign code to each symbol based on the code length array.\r
-  \r
+\r
   @param[in] LoopVar8      The number of symbols.\r
   @param[in] Len    The code length array.\r
   @param[out] Code  The stores codes for each symbol.\r
 **/\r
 VOID\r
-EFIAPI\r
 MakeCode (\r
   IN  INT32         LoopVar8,\r
   IN  UINT8 Len[    ],\r
@@ -772,7 +758,7 @@ MakeCode (
     Code[LoopVar1] = Start[Len[LoopVar1]]++;\r
   }\r
 }\r
-  \r
+\r
 /**\r
   Generates Huffman codes given a frequency distribution of symbols.\r
 \r
@@ -784,7 +770,6 @@ MakeCode (
   @return The root of the Huffman tree.\r
 **/\r
 INT32\r
-EFIAPI\r
 MakeTree (\r
   IN  INT32             NParm,\r
   IN  UINT16  FreqParm[ ],\r
@@ -868,7 +853,6 @@ MakeTree (
   @param[in] x   The data.\r
 **/\r
 VOID\r
-EFIAPI\r
 PutBits (\r
   IN INT32    LoopVar8,\r
   IN UINT32   x\r
@@ -907,7 +891,6 @@ PutBits (
   @param[in] LoopVar5     The number to encode.\r
 **/\r
 VOID\r
-EFIAPI\r
 EncodeC (\r
   IN INT32 LoopVar5\r
   )\r
@@ -921,7 +904,6 @@ EncodeC (
   @param[in] LoopVar7     The number to encode.\r
 **/\r
 VOID\r
-EFIAPI\r
 EncodeP (\r
   IN UINT32 LoopVar7\r
   )\r
@@ -948,7 +930,6 @@ EncodeP (
 \r
 **/\r
 VOID\r
-EFIAPI\r
 CountTFreq (\r
   VOID\r
   )\r
@@ -1006,7 +987,6 @@ CountTFreq (
 \r
 **/\r
 VOID\r
-EFIAPI\r
 WritePTLen (\r
   IN INT32 LoopVar8,\r
   IN INT32 nbit,\r
@@ -1045,7 +1025,6 @@ WritePTLen (
   Outputs the code length array for Char&Length Set.\r
 **/\r
 VOID\r
-EFIAPI\r
 WriteCLen (\r
   VOID\r
   )\r
@@ -1101,7 +1080,6 @@ WriteCLen (
 \r
 **/\r
 VOID\r
-EFIAPI\r
 SendBlock (\r
   VOID\r
   )\r
@@ -1175,7 +1153,6 @@ SendBlock (
 \r
 **/\r
 VOID\r
-EFIAPI\r
 HufEncodeStart (\r
   VOID\r
   )\r
@@ -1192,12 +1169,11 @@ HufEncodeStart (
 /**\r
   Outputs an Original Character or a Pointer.\r
 \r
-  @param[in] LoopVar5     The original character or the 'String Length' element of \r
+  @param[in] LoopVar5     The original character or the 'String Length' element of\r
                    a Pointer.\r
   @param[in] LoopVar7     The 'Position' field of a Pointer.\r
 **/\r
 VOID\r
-EFIAPI\r
 CompressOutput (\r
   IN UINT32 LoopVar5,\r
   IN UINT32 LoopVar7\r
@@ -1235,7 +1211,6 @@ CompressOutput (
 \r
 **/\r
 VOID\r
-EFIAPI\r
 HufEncodeEnd (\r
   VOID\r
   )\r
@@ -1255,7 +1230,6 @@ HufEncodeEnd (
   @retval EFI_OUT_0F_RESOURCES  Not enough memory for compression process.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 Encode (\r
   VOID\r
   )\r
@@ -1286,7 +1260,9 @@ Encode (
   while (mRemainder > 0) {\r
     LastMatchLen  = mMatchLen;\r
     LastMatchPos  = mMatchPos;\r
-    GetNextMatch ();\r
+    if (!GetNextMatch ()) {\r
+      Status = EFI_OUT_OF_RESOURCES;\r
+    }\r
     if (mMatchLen > mRemainder) {\r
       mMatchLen = mRemainder;\r
     }\r
@@ -1306,7 +1282,9 @@ Encode (
              (mPos - LastMatchPos - 2) & (WNDSIZ - 1));\r
       LastMatchLen--;\r
       while (LastMatchLen > 0) {\r
-        GetNextMatch ();\r
+        if (!GetNextMatch ()) {\r
+          Status = EFI_OUT_OF_RESOURCES;\r
+        }\r
         LastMatchLen--;\r
       }\r
 \r
@@ -1318,28 +1296,27 @@ Encode (
 \r
   HufEncodeEnd ();\r
   FreeMemory ();\r
-  return EFI_SUCCESS;\r
+  return (Status);\r
 }\r
 \r
 /**\r
   The compression routine.\r
 \r
-  @param[in]      SrcBuffer     The buffer containing the source data.\r
-  @param[in]      SrcSize       The number of bytes in SrcBuffer.\r
-  @param[in]      DstBuffer     The buffer to put the compressed image in.\r
-  @param[in,out]  DstSize       On input the size (in bytes) of DstBuffer, on\r
-                                return the number of bytes placed in DstBuffer.\r
+  @param[in]       SrcBuffer     The buffer containing the source data.\r
+  @param[in]       SrcSize       Number of bytes in SrcBuffer.\r
+  @param[in]       DstBuffer     The buffer to put the compressed image in.\r
+  @param[in, out]  DstSize       On input the size (in bytes) of DstBuffer, on\r
+                                 return the number of bytes placed in DstBuffer.\r
 \r
   @retval EFI_SUCCESS           The compression was sucessful.\r
   @retval EFI_BUFFER_TOO_SMALL  The buffer was too small.  DstSize is required.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 Compress (\r
-  IN       VOID   *SrcBuffer,\r
-  IN       UINT64 SrcSize,\r
-  IN       VOID   *DstBuffer,\r
-  IN OUT   UINT64 *DstSize\r
+  IN      VOID    *SrcBuffer,\r
+  IN      UINT64  SrcSize,\r
+  IN      VOID    *DstBuffer,\r
+  IN OUT  UINT64  *DstSize\r
   )\r
 {\r
   EFI_STATUS  Status;\r