]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellDebug1CommandsLib/Compress.c
ShellPkg: Make the USB mouse behavior in 'edit' consistent with 'hexedit'.
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / Compress.c
index afe3ec08582a489630c49bfbeb5aa7f9f8e19533..210618579801fa3542a01d936b722b89860f6d12 100644 (file)
@@ -7,7 +7,7 @@
   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
+  Copyright (c) 2007 - 2014, 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
@@ -22,6 +22,7 @@
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <ShellBase.h>\r
+#include <Uefi.h>\r
 \r
 //\r
 // Macro Definitions\r
@@ -237,8 +238,7 @@ FreeMemory (
 }\r
 \r
 /**\r
-  Initialize String Info Log data structures\r
-\r
+  Initialize String Info Log data structures.\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -608,8 +608,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
+BOOLEAN\r
 EFIAPI\r
 GetNextMatch (\r
   VOID\r
@@ -622,6 +624,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
@@ -632,6 +637,8 @@ GetNextMatch (
 \r
   DeleteNode ();\r
   InsertNode ();\r
+\r
+  return (TRUE);\r
 }\r
 \r
 /**\r
@@ -1043,8 +1050,7 @@ WritePTLen (
 }\r
 \r
 /**\r
-  Outputs the code length array for Char&Length Set\r
-\r
+  Outputs the code length array for Char&Length Set.\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -1288,7 +1294,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
@@ -1308,7 +1316,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
@@ -1320,16 +1330,16 @@ 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
+  @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
 \r
   @retval EFI_SUCCESS           The compression was sucessful.\r