X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=BaseTools%2FSource%2FC%2FVfrCompile%2FVfrCompiler.cpp;h=0e9c2df48d93b1ef09b8fa7caaf2ba3bb7e65350;hb=543f5ac30facfbb40eafb2b4908649a427784080;hp=16453439ec0b148bec6368b0dd408361037c7431;hpb=a6ac965bca117ef33b38a96c36643b36757b7698;p=mirror_edk2.git
diff --git a/BaseTools/Source/C/VfrCompile/VfrCompiler.cpp b/BaseTools/Source/C/VfrCompile/VfrCompiler.cpp
index 16453439ec..0e9c2df48d 100644
--- a/BaseTools/Source/C/VfrCompile/VfrCompiler.cpp
+++ b/BaseTools/Source/C/VfrCompile/VfrCompiler.cpp
@@ -1,15 +1,15 @@
/** @file
-
+
VfrCompiler main class and main function.
-Copyright (c) 2004 - 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
-http://opensource.org/licenses/bsd-license.php
-
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+Copyright (c) 2004 - 2018, 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
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
@@ -24,7 +24,7 @@ PACKAGE_DATA gCBuffer;
PACKAGE_DATA gRBuffer;
CVfrStringDB gCVfrStringDB;
-VOID
+VOID
CVfrCompiler::DebugError (
IN CHAR8 *FileName,
IN UINT32 LineNumber,
@@ -32,7 +32,7 @@ CVfrCompiler::DebugError (
IN CONST CHAR8 *Text,
IN CONST CHAR8 *MsgFmt,
...
- )
+ )
{
va_list List;
va_start (List, MsgFmt);
@@ -58,7 +58,7 @@ CVfrCompiler::IS_RUN_STATUS (
VOID
CVfrCompiler::OptionInitialization (
- IN INT32 Argc,
+ IN INT32 Argc,
IN CHAR8 **Argv
)
{
@@ -86,7 +86,7 @@ CVfrCompiler::OptionInitialization (
mOptions.AutoDefault = FALSE;
mOptions.CheckDefault = FALSE;
memset (&mOptions.OverrideClassGuid, 0, sizeof (EFI_GUID));
-
+
if (Argc == 1) {
Usage ();
SET_RUN_STATUS (STATUS_DEAD);
@@ -108,7 +108,7 @@ CVfrCompiler::OptionInitialization (
} else if (stricmp(Argv[Index], "-i") == 0) {
Index++;
if ((Index >= Argc) || (Argv[Index][0] == '-')) {
- DebugError (NULL, 0, 1001, "Missing option", "-i missing path argument");
+ DebugError (NULL, 0, 1001, "Missing option", "-i missing path argument");
goto Fail;
}
@@ -119,10 +119,6 @@ CVfrCompiler::OptionInitialization (
DebugError (NULL, 0, 1001, "Missing option", "-o missing output directory name");
goto Fail;
}
- if (strlen (Argv[Index]) > MAX_PATH - 1) {
- DebugError (NULL, 0, 1003, "Invalid option value", "Output directory name %s is too long", Argv[Index]);
- goto Fail;
- }
mOptions.OutputDirectory = (CHAR8 *) malloc (strlen (Argv[Index]) + strlen ("\\") + 1);
if (mOptions.OutputDirectory == NULL) {
@@ -130,7 +126,7 @@ CVfrCompiler::OptionInitialization (
goto Fail;
}
strcpy (mOptions.OutputDirectory, Argv[Index]);
-
+
CHAR8 lastChar = mOptions.OutputDirectory[strlen(mOptions.OutputDirectory) - 1];
if ((lastChar != '/') && (lastChar != '\\')) {
if (strchr(mOptions.OutputDirectory, '/') != NULL) {
@@ -139,7 +135,7 @@ CVfrCompiler::OptionInitialization (
strcat (mOptions.OutputDirectory, "\\");
}
}
- DebugMsg (NULL, 0, 9, (CHAR8 *) "Output Directory", mOptions.OutputDirectory);
+ DebugMsg (NULL, 0, 9, (CHAR8 *) "Output Directory", (CHAR8 *) "%s", mOptions.OutputDirectory);
} else if (stricmp(Argv[Index], "-b") == 0 || stricmp(Argv[Index], "--create-ifr-package") == 0 || stricmp(Argv[Index], "-ibin") == 0) {
mOptions.CreateIfrPkgFile = TRUE;
} else if (stricmp(Argv[Index], "-n") == 0 || stricmp(Argv[Index], "--no-pre-processing") == 0 || stricmp(Argv[Index], "-nopp") == 0) {
@@ -161,7 +157,7 @@ CVfrCompiler::OptionInitialization (
goto Fail;
}
gCVfrStringDB.SetStringFileName(Argv[Index]);
- DebugMsg (NULL, 0, 9, (CHAR8 *) "Input string file path", Argv[Index]);
+ DebugMsg (NULL, 0, 9, (CHAR8 *) "Input string file path", (CHAR8 *) "%s", Argv[Index]);
} else if ((stricmp (Argv[Index], "-g") == 0) || (stricmp (Argv[Index], "--guid") == 0)) {
Index++;
Status = StringToGuid (Argv[Index], &mOptions.OverrideClassGuid);
@@ -186,10 +182,6 @@ CVfrCompiler::OptionInitialization (
DebugError (NULL, 0, 1001, "Missing option", "VFR file name is not specified.");
goto Fail;
} else {
- if (strlen (Argv[Index]) > MAX_PATH) {
- DebugError (NULL, 0, 1003, "Invalid option value", "VFR file name %s is too long.", Argv[Index]);
- goto Fail;
- }
mOptions.VfrFileName = (CHAR8 *) malloc (strlen (Argv[Index]) + 1);
if (mOptions.VfrFileName == NULL) {
DebugError (NULL, 0, 4001, "Resource: memory can't be allocated", NULL);
@@ -261,7 +253,7 @@ Fail:
if (mOptions.IncludePaths != NULL) {
delete mOptions.IncludePaths;
mOptions.IncludePaths = NULL;
- }
+ }
if (mOptions.CPreprocessorOptions != NULL) {
delete mOptions.CPreprocessorOptions;
mOptions.CPreprocessorOptions = NULL;
@@ -292,7 +284,7 @@ CVfrCompiler::AppendIncludePath (
strcat (IncludePaths, " -I ");
strcat (IncludePaths, PathStr);
if (mOptions.IncludePaths != NULL) {
- delete mOptions.IncludePaths;
+ delete[] mOptions.IncludePaths;
}
mOptions.IncludePaths = IncludePaths;
}
@@ -321,7 +313,7 @@ CVfrCompiler::AppendCPreprocessorOptions (
strcat (Opt, " ");
strcat (Opt, Options);
if (mOptions.CPreprocessorOptions != NULL) {
- delete mOptions.CPreprocessorOptions;
+ delete[] mOptions.CPreprocessorOptions;
}
mOptions.CPreprocessorOptions = Opt;
}
@@ -355,10 +347,6 @@ CVfrCompiler::SetBaseFileName (
}
*pExt = '\0';
- if (strlen (pFileName) > MAX_PATH - 1) {
- *pExt = '.';
- return -1;
- }
mOptions.VfrBaseFileName = (CHAR8 *) malloc (strlen (pFileName) + 1);
if (mOptions.VfrBaseFileName == NULL) {
@@ -387,9 +375,6 @@ CVfrCompiler::SetPkgOutputFileName (
strlen (mOptions.VfrBaseFileName) +
strlen (VFR_PACKAGE_FILENAME_EXTENSION) +
1;
- if (Length > MAX_PATH) {
- return -1;
- }
mOptions.PkgOutputFileName = (CHAR8 *) malloc (Length);
if (mOptions.PkgOutputFileName == NULL) {
@@ -418,9 +403,6 @@ CVfrCompiler::SetCOutputFileName (
strlen (mOptions.VfrBaseFileName) +
strlen (".c") +
1;
- if (Length > MAX_PATH) {
- return -1;
- }
mOptions.COutputFileName = (CHAR8 *) malloc (Length);
if (mOptions.COutputFileName == NULL) {
@@ -449,9 +431,6 @@ CVfrCompiler::SetPreprocessorOutputFileName (
strlen (mOptions.VfrBaseFileName) +
strlen (VFR_PREPROCESS_FILENAME_EXTENSION) +
1;
- if (Length > MAX_PATH) {
- return -1;
- }
mOptions.PreprocessorOutputFileName = (CHAR8 *) malloc (Length);
if (mOptions.PreprocessorOutputFileName == NULL) {
@@ -480,9 +459,6 @@ CVfrCompiler::SetRecordListFileName (
strlen (mOptions.VfrBaseFileName) +
strlen (VFR_RECORDLIST_FILENAME_EXTENSION) +
1;
- if (Length > MAX_PATH) {
- return -1;
- }
mOptions.RecordListFile = (CHAR8 *) malloc (Length);
if (mOptions.RecordListFile == NULL) {
@@ -497,7 +473,7 @@ CVfrCompiler::SetRecordListFileName (
}
CVfrCompiler::CVfrCompiler (
- IN INT32 Argc,
+ IN INT32 Argc,
IN CHAR8 **Argv
)
{
@@ -555,26 +531,26 @@ CVfrCompiler::~CVfrCompiler (
}
if (mOptions.IncludePaths != NULL) {
- delete mOptions.IncludePaths;
+ delete[] mOptions.IncludePaths;
mOptions.IncludePaths = NULL;
}
if (mOptions.CPreprocessorOptions != NULL) {
- delete mOptions.CPreprocessorOptions;
+ delete[] mOptions.CPreprocessorOptions;
mOptions.CPreprocessorOptions = NULL;
}
SET_RUN_STATUS(STATUS_DEAD);
}
-VOID
+VOID
CVfrCompiler::Usage (
VOID
)
{
UINT32 Index;
CONST CHAR8 *Help[] = {
- " ",
+ " ",
"VfrCompile version " VFR_COMPILER_VERSION "Build " __BUILD_VERSION,
"Copyright (c) 2004-2016 Intel Corporation. All rights reserved.",
" ",
@@ -609,7 +585,7 @@ CVfrCompiler::Usage (
}
}
-VOID
+VOID
CVfrCompiler::Version (
VOID
)
@@ -642,13 +618,13 @@ CVfrCompiler::PreProcess (
}
if ((pVfrFile = fopen (LongFilePath (mOptions.VfrFileName), "r")) == NULL) {
- DebugError (NULL, 0, 0001, "Error opening the input VFR file", mOptions.VfrFileName);
+ DebugError (NULL, 0, 0001, "Error opening the input VFR file", "%s", mOptions.VfrFileName);
goto Fail;
}
fclose (pVfrFile);
- CmdLen = strlen (mPreProcessCmd) + strlen (mPreProcessOpt) +
- strlen (mOptions.VfrFileName) + strlen (mOptions.PreprocessorOutputFileName);
+ CmdLen = strlen (mPreProcessCmd) + strlen (mPreProcessOpt) +
+ strlen (mOptions.VfrFileName) + strlen (mOptions.PreprocessorOutputFileName);
if (mOptions.CPreprocessorOptions != NULL) {
CmdLen += strlen (mOptions.CPreprocessorOptions);
}
@@ -677,7 +653,7 @@ CVfrCompiler::PreProcess (
goto Fail;
}
- delete PreProcessCmd;
+ delete[] PreProcessCmd;
Out:
SET_RUN_STATUS (STATUS_PREPROCESSED);
@@ -687,7 +663,7 @@ Fail:
if (!IS_RUN_STATUS(STATUS_DEAD)) {
SET_RUN_STATUS (STATUS_FAILED);
}
- delete PreProcessCmd;
+ delete[] PreProcessCmd;
}
extern UINT8 VfrParserStart (IN FILE *, IN INPUT_INFO_TO_SYNTAX *);
@@ -711,7 +687,7 @@ CVfrCompiler::Compile (
gCVfrErrorHandle.SetWarningAsError(mOptions.WarningAsError);
if ((pInFile = fopen (LongFilePath (InFileName), "r")) == NULL) {
- DebugError (NULL, 0, 0001, "Error opening the input file", InFileName);
+ DebugError (NULL, 0, 0001, "Error opening the input file", "%s", InFileName);
goto Fail;
}
@@ -727,6 +703,7 @@ CVfrCompiler::Compile (
}
fclose (pInFile);
+ pInFile = NULL;
if (gCFormPkg.HavePendingUnassigned () == TRUE) {
gCFormPkg.PendingAssignPrintAll ();
@@ -779,7 +756,7 @@ CVfrCompiler::AdjustBin (
// Get Package Data and IfrRecord Data
//
gCFormPkg.BuildPkg (gCBuffer);
- gCIfrRecordInfoDB.IfrRecordOutput (gRBuffer);
+ gCIfrRecordInfoDB.IfrRecordOutput (gRBuffer);
//
// Compare Form and Record data
@@ -822,7 +799,7 @@ CVfrCompiler::AdjustBin (
//
// Re get the IfrRecord Buffer.
//
- gCIfrRecordInfoDB.IfrRecordOutput (gRBuffer);
+ gCIfrRecordInfoDB.IfrRecordOutput (gRBuffer);
}
return;
@@ -841,7 +818,7 @@ CVfrCompiler::GenBinary (
if (mOptions.CreateIfrPkgFile == TRUE) {
if ((pFile = fopen (LongFilePath (mOptions.PkgOutputFileName), "wb")) == NULL) {
- DebugError (NULL, 0, 0001, "Error opening file", mOptions.PkgOutputFileName);
+ DebugError (NULL, 0, 0001, "Error opening file", "%s", mOptions.PkgOutputFileName);
goto Fail;
}
if (gCFormPkg.BuildPkg (pFile, &gRBuffer) != VFR_RETURN_SUCCESS) {
@@ -881,10 +858,10 @@ CVfrCompiler::GenCFile (
if (!IS_RUN_STATUS(STATUS_GENBINARY)) {
goto Fail;
}
-
+
if (!mOptions.CreateIfrPkgFile || mOptions.CompatibleMode) {
if ((pFile = fopen (LongFilePath (mOptions.COutputFileName), "w")) == NULL) {
- DebugError (NULL, 0, 0001, "Error opening output C file", mOptions.COutputFileName);
+ DebugError (NULL, 0, 0001, "Error opening output C file", "%s", mOptions.COutputFileName);
goto Fail;
}
@@ -892,7 +869,7 @@ CVfrCompiler::GenCFile (
fprintf (pFile, "%s\n", gSourceFileHeader[Index]);
}
- if (mOptions.CompatibleMode) {
+ if (mOptions.CompatibleMode) {
gCVfrBufferConfig.OutputCFile (pFile, mOptions.VfrBaseFileName);
}
@@ -925,18 +902,18 @@ CVfrCompiler::GenRecordListFile (
InFileName = (mOptions.SkipCPreprocessor == TRUE) ? mOptions.VfrFileName : mOptions.PreprocessorOutputFileName;
- if (mOptions.CreateRecordListFile == TRUE) {
+ if (mOptions.CreateRecordListFile == TRUE && InFileName != NULL && mOptions.RecordListFile != NULL) {
if ((InFileName[0] == '\0') || (mOptions.RecordListFile[0] == '\0')) {
return;
}
if ((pInFile = fopen (LongFilePath (InFileName), "r")) == NULL) {
- DebugError (NULL, 0, 0001, "Error opening the input VFR preprocessor output file", InFileName);
+ DebugError (NULL, 0, 0001, "Error opening the input VFR preprocessor output file", "%s", InFileName);
return;
}
if ((pOutFile = fopen (LongFilePath (mOptions.RecordListFile), "w")) == NULL) {
- DebugError (NULL, 0, 0001, "Error opening the record list file", mOptions.RecordListFile);
+ DebugError (NULL, 0, 0001, "Error opening the record list file", "%s", mOptions.RecordListFile);
goto Err1;
}
@@ -949,7 +926,7 @@ CVfrCompiler::GenRecordListFile (
gCIfrRecordInfoDB.IfrRecordOutput (pOutFile, LineNo);
}
}
-
+
fprintf (pOutFile, "\n//\n// All Opcode Record List \n//\n");
gCIfrRecordInfoDB.IfrRecordOutput (pOutFile, 0);
gCVfrVarDataTypeDB.Dump(pOutFile);
@@ -966,7 +943,7 @@ Err1:
int
main (
- IN int Argc,
+ IN int Argc,
IN char **Argv
)
{
@@ -974,7 +951,7 @@ main (
SetPrintLevel(WARNING_LOG_LEVEL);
CVfrCompiler Compiler(Argc, Argv);
-
+
Compiler.PreProcess();
Compiler.Compile();
Compiler.AdjustBin();
@@ -988,11 +965,11 @@ main (
}
if (gCBuffer.Buffer != NULL) {
- delete gCBuffer.Buffer;
+ delete[] gCBuffer.Buffer;
}
-
+
if (gRBuffer.Buffer != NULL) {
- delete gRBuffer.Buffer;
+ delete[] gRBuffer.Buffer;
}
return GetUtilityStatus ();