This sequence is further divided into Blocks and Huffman codings are applied to \r
each Block.\r
\r
-Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2016, 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
UINT32 Index;\r
\r
mText = malloc (WNDSIZ * 2 + MAXMATCH);\r
+ if (mText == NULL) {\r
+ Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
for (Index = 0; Index < WNDSIZ * 2 + MAXMATCH; Index++) {\r
mText[Index] = 0;\r
}\r
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
+ Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
\r
mBufSiz = BLKSIZ;\r
mBuf = malloc (mBufSiz);\r
InputLength = 0;\r
InputFileName = NULL;\r
OutputFileName = NULL;\r
+ InputFile = NULL;\r
+ OutputFile = NULL;\r
DstSize=0;\r
DebugLevel = 0;\r
DebugMode = FALSE;\r
FileBuffer = (UINT8 *) malloc (InputLength);\r
if (FileBuffer == NULL) {\r
Error (NULL, 0, 4001, "Resource:", "Memory cannot be allocated!");\r
- return 1;\r
+ goto ERROR;\r
}\r
\r
Status = GetFileContents (\r
}\r
\r
if (EFI_ERROR(Status)) {\r
- free(FileBuffer);\r
- return 1;\r
+ Error (NULL, 0, 0004, "Error getting contents of file: %s", InputFileName);\r
+ goto ERROR;\r
+ }\r
+\r
+ if (OutputFileName == NULL) {\r
+ OutputFileName = DEFAULT_OUTPUT_FILE;\r
+ }\r
+ OutputFile = fopen (LongFilePath (OutputFileName), "wb");\r
+ if (OutputFile == NULL) {\r
+ Error (NULL, 0, 0001, "Error opening output file for writing", OutputFileName);\r
+ goto ERROR;\r
}\r
- \r
- if (OutputFileName != NULL) {\r
- OutputFile = fopen (LongFilePath (OutputFileName), "wb");\r
- if (OutputFile == NULL) {\r
- Error (NULL, 0, 0001, "Error opening output file for writing", OutputFileName);\r
- if (InputFile != NULL) {\r
- fclose (InputFile);\r
- }\r
- goto ERROR;\r
- }\r
- } else {\r
- OutputFileName = DEFAULT_OUTPUT_FILE;\r
- OutputFile = fopen (LongFilePath (OutputFileName), "wb");\r
- }\r
\r
if (ENCODE) {\r
//\r
goto ERROR;\r
}\r
}\r
+\r
Status = TianoCompress ((UINT8 *)FileBuffer, InputLength, OutBuffer, &DstSize);\r
if (Status != EFI_SUCCESS) {\r
Error (NULL, 0, 0007, "Error compressing file", NULL);\r
goto ERROR;\r
}\r
\r
+ if (OutBuffer == NULL) {\r
+ Error (NULL, 0, 4001, "Resource:", "Memory cannot be allocated!");\r
+ goto ERROR;\r
+ }\r
+\r
fwrite(OutBuffer,(size_t)DstSize, 1, OutputFile);\r
+ fclose(OutputFile);\r
+ fclose(InputFile);\r
free(Scratch);\r
free(FileBuffer);\r
free(OutBuffer);\r
}\r
\r
fwrite(OutBuffer, (size_t)(Scratch->mOrigSize), 1, OutputFile);\r
+ fclose(OutputFile);\r
+ fclose(InputFile);\r
free(Scratch);\r
free(FileBuffer);\r
free(OutBuffer);\r
DebugMsg(UTILITY_NAME, 0, DebugLevel, "Decoding Error\n", NULL);\r
}\r
}\r
+ if (OutputFile != NULL) {\r
+ fclose(OutputFile);\r
+ }\r
+ if (InputFile != NULL) {\r
+ fclose (InputFile);\r
+ }\r
if (Scratch != NULL) {\r
free(Scratch);\r
}\r
\r
--*/\r
{\r
- Sd->mBitBuf = (UINT32) (Sd->mBitBuf << NumOfBits);\r
+ Sd->mBitBuf = (UINT32) (((UINT64)Sd->mBitBuf) << NumOfBits);\r
\r
while (NumOfBits > Sd->mBitCount) {\r
\r
- Sd->mBitBuf |= (UINT32) (Sd->mSubBitBuf << (NumOfBits = (UINT16) (NumOfBits - Sd->mBitCount)));\r
+ Sd->mBitBuf |= (UINT32) (((UINT64)Sd->mSubBitBuf) << (NumOfBits = (UINT16) (NumOfBits - Sd->mBitCount)));\r
\r
if (Sd->mCompSize > 0) {\r
//\r
UINT16 Start[18];\r
UINT16 *Pointer;\r
UINT16 Index3;\r
- volatile UINT16 Index;\r
+ UINT16 Index;\r
UINT16 Len;\r
UINT16 Char;\r
UINT16 JuBits;\r
UINT16 WordOfStart;\r
UINT16 WordOfCount;\r
\r
- for (Index = 1; Index <= 16; Index++) {\r
+ for (Index = 0; Index <= 16; Index++) {\r
Count[Index] = 0;\r
}\r
\r
Count[BitLen[Index]]++;\r
}\r
\r
+ Start[0] = 0;\r
Start[1] = 0;\r
\r
for (Index = 1; Index <= 16; Index++) {\r
\r
JuBits = (UINT16) (16 - TableBits);\r
\r
+ Weight[0] = 0;\r
for (Index = 1; Index <= TableBits; Index++) {\r
Start[Index] >>= JuBits;\r
Weight[Index] = (UINT16) (1U << (TableBits - Index));\r
for (Char = 0; Char < NumOfChar; Char++) {\r
\r
Len = BitLen[Char];\r
- if (Len == 0) {\r
+ if (Len == 0 || Len >= 17) {\r
continue;\r
}\r
\r
volatile UINT16 Index;\r
UINT32 Mask;\r
\r
+ assert (nn <= NPT);\r
+\r
Number = (UINT16) GetBits (Sd, nbit);\r
\r
if (Number == 0) {\r