]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/Common/TianoCompress.c
BaseTools: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / BaseTools / Source / C / Common / TianoCompress.c
index a34f1d2a7d5b68f228176641a1c4e466a1b7c34a..030cdca025b8ef9d963126a1ec53be471c3a11ba 100644 (file)
@@ -1,25 +1,11 @@
 /** @file\r
+Compression routine. The compression algorithm is a mixture of LZ77 and Huffman\r
+coding. LZ77 transforms the source data into a sequence of Original Characters\r
+and Pointers to repeated strings. This sequence is further divided into Blocks\r
+and Huffman codings are applied to each Block.\r
 \r
-Copyright (c) 2006 - 2008, 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
-\r
-Module Name:\r
-\r
-  TianoCompress.c\r
-\r
-Abstract:\r
-\r
-  Compression routine. The compression algorithm is a mixture of\r
-  LZ77 and Huffman coding. LZ77 transforms the source data into a\r
-  sequence of Original Characters and Pointers to repeated strings.\r
-  This sequence is further divided into Blocks and Huffman codings\r
-  are applied to each Block.\r
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -375,13 +361,13 @@ PutDword (
 Routine Description:\r
 \r
   Put a dword to output stream\r
-  \r
+\r
 Arguments:\r
 \r
   Data    - the dword to put\r
-  \r
+\r
 Returns: (VOID)\r
-  \r
+\r
 --*/\r
 {\r
   if (mDst < mDstUpperLimit) {\r
@@ -411,8 +397,8 @@ AllocateMemory (
 Routine Description:\r
 \r
   Allocate memory spaces for data structures used in compression process\r
-  \r
-Argements: \r
+\r
+Arguments:\r
   VOID\r
 \r
 Returns:\r
@@ -425,6 +411,9 @@ Returns:
   UINT32  Index;\r
 \r
   mText = malloc (WNDSIZ * 2 + MAXMATCH);\r
+  if (mText == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
   for (Index = 0; Index < WNDSIZ * 2 + MAXMATCH; Index++) {\r
     mText[Index] = 0;\r
   }\r
@@ -435,6 +424,10 @@ Returns:
   mParent     = malloc (WNDSIZ * 2 * sizeof (*mParent));\r
   mPrev       = malloc (WNDSIZ * 2 * sizeof (*mPrev));\r
   mNext       = malloc ((MAX_HASH_VAL + 1) * sizeof (*mNext));\r
+  if (mLevel == NULL || mChildCount == NULL || mPosition == NULL ||\r
+    mParent == NULL || mPrev == NULL || mNext == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
 \r
   mBufSiz     = BLKSIZ;\r
   mBuf        = malloc (mBufSiz);\r
@@ -461,7 +454,7 @@ FreeMemory (
 Routine Description:\r
 \r
   Called when compression is completed to free memory previously allocated.\r
-  \r
+\r
 Arguments: (VOID)\r
 \r
 Returns: (VOID)\r
@@ -513,7 +506,7 @@ InitSlide (
 Routine Description:\r
 \r
   Initialize String Info Log data structures\r
-  \r
+\r
 Arguments: (VOID)\r
 \r
 Returns: (VOID)\r
@@ -553,16 +546,16 @@ Child (
 Routine Description:\r
 \r
   Find child node given the parent node and the edge character\r
-  \r
+\r
 Arguments:\r
 \r
   NodeQ       - the parent node\r
   CharC       - the edge character\r
-  \r
+\r
 Returns:\r
 \r
-  The child node (NIL if not found)  \r
-  \r
+  The child node (NIL if not found)\r
+\r
 --*/\r
 {\r
   NODE  NodeR;\r
@@ -591,13 +584,13 @@ MakeChild (
 Routine Description:\r
 \r
   Create a new child for a given parent node.\r
-  \r
+\r
 Arguments:\r
 \r
   Parent       - the parent node\r
   CharC   - the edge character\r
   Child       - the child node\r
-  \r
+\r
 Returns: (VOID)\r
 \r
 --*/\r
@@ -625,11 +618,11 @@ Split (
 Routine Description:\r
 \r
   Split a node.\r
-  \r
+\r
 Arguments:\r
 \r
   Old     - the node to split\r
-  \r
+\r
 Returns: (VOID)\r
 \r
 --*/\r
@@ -663,7 +656,7 @@ InsertNode (
 Routine Description:\r
 \r
   Insert string info for current position into the String Info Log\r
-  \r
+\r
 Arguments: (VOID)\r
 \r
 Returns: (VOID)\r
@@ -681,7 +674,7 @@ Returns: (VOID)
   if (mMatchLen >= 4) {\r
     //\r
     // We have just got a long match, the target tree\r
-    // can be located by MatchPos + 1. Travese the tree\r
+    // can be located by MatchPos + 1. Traverse the tree\r
     // from bottom up to get to a proper starting point.\r
     // The usage of PERC_FLAG ensures proper node deletion\r
     // in DeleteNode() later.\r
@@ -796,7 +789,7 @@ Routine Description:
 \r
   Delete outdated string info. (The Usage of PERC_FLAG\r
   ensures a clean deletion)\r
-  \r
+\r
 Arguments: (VOID)\r
 \r
 Returns: (VOID)\r
@@ -927,7 +920,7 @@ Routine Description:
 Arguments: (VOID)\r
 \r
 Returns:\r
-  \r
+\r
   EFI_SUCCESS           - The compression is successful\r
   EFI_OUT_0F_RESOURCES  - Not enough memory for compression process\r
 \r
@@ -1013,7 +1006,7 @@ CountTFreq (
 Routine Description:\r
 \r
   Count the frequencies for the Extra Set\r
-  \r
+\r
 Arguments: (VOID)\r
 \r
 Returns: (VOID)\r
@@ -1072,13 +1065,13 @@ WritePTLen (
 Routine Description:\r
 \r
   Outputs the code length array for the Extra Set or the Position Set.\r
-  \r
+\r
 Arguments:\r
 \r
   Number       - the number of symbols\r
   nbit    - the number of bits needed to represent 'n'\r
   Special - the special symbol that needs to be take care of\r
-  \r
+\r
 Returns: (VOID)\r
 \r
 --*/\r
@@ -1120,7 +1113,7 @@ WriteCLen (
 Routine Description:\r
 \r
   Outputs the code length array for Char&Length Set\r
-  \r
+\r
 Arguments: (VOID)\r
 \r
 Returns: (VOID)\r
@@ -1210,11 +1203,11 @@ SendBlock (
 Routine Description:\r
 \r
   Huffman code the block and output it.\r
-  \r
-Arguments: \r
+\r
+Arguments:\r
   (VOID)\r
 \r
-Returns: \r
+Returns:\r
   (VOID)\r
 \r
 --*/\r
@@ -1421,7 +1414,7 @@ Routine Description:
 Arguments:\r
 \r
   Number   - the rightmost n bits of the data is used\r
-  x   - the data \r
+  x   - the data\r
 \r
 Returns: (VOID)\r
 \r
@@ -1457,7 +1450,7 @@ FreadCrc (
 Routine Description:\r
 \r
   Read in source data\r
-  \r
+\r
 Arguments:\r
 \r
   Pointer   - the buffer to hold the data\r
@@ -1466,7 +1459,7 @@ Arguments:
 Returns:\r
 \r
   number of bytes actually read\r
-  \r
+\r
 --*/\r
 {\r
   INT32 Index;\r
@@ -1508,11 +1501,11 @@ CountLen (
 Routine Description:\r
 \r
   Count the number of each code length for a Huffman tree.\r
-  \r
+\r
 Arguments:\r
 \r
   Index   - the top node\r
-  \r
+\r
 Returns: (VOID)\r
 \r
 --*/\r
@@ -1539,11 +1532,11 @@ MakeLen (
 Routine Description:\r
 \r
   Create code length array for a Huffman tree\r
-  \r
+\r
 Arguments:\r
 \r
   Root   - the root of the tree\r
-  \r
+\r
 Returns:\r
 \r
   VOID\r
@@ -1635,7 +1628,7 @@ MakeCode (
 Routine Description:\r
 \r
   Assign code to each symbol based on the code length array\r
-  \r
+\r
 Arguments:\r
 \r
   Number     - number of symbols\r
@@ -1672,18 +1665,18 @@ MakeTree (
 Routine Description:\r
 \r
   Generates Huffman codes given a frequency distribution of symbols\r
-  \r
+\r
 Arguments:\r
 \r
   NParm    - number of symbols\r
   FreqParm - frequency of each symbol\r
   LenParm  - code length for each symbol\r
   CodeParm - code for each symbol\r
-  \r
+\r
 Returns:\r
 \r
   Root of the Huffman tree.\r
-  \r
+\r
 --*/\r
 {\r
   INT32 Index;\r