]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/VfrCompile/VfrCompiler.cpp
BaseTool/VfrCompile: make delete[] match with new[]
[mirror_edk2.git] / BaseTools / Source / C / VfrCompile / VfrCompiler.cpp
index ff7057a64f4ca751f8da07bd45de8f9e2c5e6a50..84c0e59b76f2c47af519066d8cbb000e0d568966 100644 (file)
@@ -2,7 +2,7 @@
   \r
   VfrCompiler main class and main function.\r
 \r
-Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2018, 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
@@ -119,10 +119,6 @@ CVfrCompiler::OptionInitialization (
         DebugError (NULL, 0, 1001, "Missing option", "-o missing output directory name");\r
         goto Fail;\r
       }\r
-      if (strlen (Argv[Index]) > MAX_PATH - 1) {\r
-        DebugError (NULL, 0, 1003, "Invalid option value", "Output directory name %s is too long", Argv[Index]);\r
-        goto Fail;\r
-      }\r
 \r
       mOptions.OutputDirectory = (CHAR8 *) malloc (strlen (Argv[Index]) + strlen ("\\") + 1);\r
       if (mOptions.OutputDirectory == NULL) {\r
@@ -186,10 +182,6 @@ CVfrCompiler::OptionInitialization (
     DebugError (NULL, 0, 1001, "Missing option", "VFR file name is not specified.");\r
     goto Fail;\r
   } else {\r
-    if (strlen (Argv[Index]) > MAX_PATH) {\r
-      DebugError (NULL, 0, 1003, "Invalid option value", "VFR file name %s is too long.", Argv[Index]);\r
-      goto Fail;\r
-    }\r
     mOptions.VfrFileName = (CHAR8 *) malloc (strlen (Argv[Index]) + 1);\r
     if (mOptions.VfrFileName == NULL) {\r
       DebugError (NULL, 0, 4001, "Resource: memory can't be allocated", NULL);\r
@@ -292,7 +284,7 @@ CVfrCompiler::AppendIncludePath (
   strcat (IncludePaths, " -I ");\r
   strcat (IncludePaths, PathStr);\r
   if (mOptions.IncludePaths != NULL) {\r
-    delete mOptions.IncludePaths;\r
+    delete[] mOptions.IncludePaths;\r
   }\r
   mOptions.IncludePaths = IncludePaths;\r
 }\r
@@ -321,7 +313,7 @@ CVfrCompiler::AppendCPreprocessorOptions (
   strcat (Opt, " ");\r
   strcat (Opt, Options);\r
   if (mOptions.CPreprocessorOptions != NULL) {\r
-    delete mOptions.CPreprocessorOptions;\r
+    delete[] mOptions.CPreprocessorOptions;\r
   }\r
   mOptions.CPreprocessorOptions = Opt;\r
 }\r
@@ -355,10 +347,6 @@ CVfrCompiler::SetBaseFileName (
   }\r
 \r
   *pExt = '\0';\r
-  if (strlen (pFileName) > MAX_PATH - 1) {\r
-    *pExt = '.';\r
-    return -1;\r
-  }\r
 \r
   mOptions.VfrBaseFileName = (CHAR8 *) malloc (strlen (pFileName) + 1);\r
   if (mOptions.VfrBaseFileName == NULL) {\r
@@ -387,9 +375,6 @@ CVfrCompiler::SetPkgOutputFileName (
            strlen (mOptions.VfrBaseFileName) +\r
            strlen (VFR_PACKAGE_FILENAME_EXTENSION) +\r
            1;\r
-  if (Length > MAX_PATH) {\r
-    return -1;\r
-  }\r
 \r
   mOptions.PkgOutputFileName = (CHAR8 *) malloc (Length);\r
   if (mOptions.PkgOutputFileName == NULL) {\r
@@ -418,9 +403,6 @@ CVfrCompiler::SetCOutputFileName (
            strlen (mOptions.VfrBaseFileName) +\r
            strlen (".c") +\r
            1;\r
-  if (Length > MAX_PATH) {\r
-    return -1;\r
-  }\r
 \r
   mOptions.COutputFileName = (CHAR8 *) malloc (Length);\r
   if (mOptions.COutputFileName == NULL) {\r
@@ -449,9 +431,6 @@ CVfrCompiler::SetPreprocessorOutputFileName (
            strlen (mOptions.VfrBaseFileName) +\r
            strlen (VFR_PREPROCESS_FILENAME_EXTENSION) +\r
            1;\r
-  if (Length > MAX_PATH) {\r
-    return -1;\r
-  }\r
 \r
   mOptions.PreprocessorOutputFileName = (CHAR8 *) malloc (Length);\r
   if (mOptions.PreprocessorOutputFileName == NULL) {\r
@@ -480,9 +459,6 @@ CVfrCompiler::SetRecordListFileName (
            strlen (mOptions.VfrBaseFileName) +\r
            strlen (VFR_RECORDLIST_FILENAME_EXTENSION) +\r
            1;\r
-  if (Length > MAX_PATH) {\r
-    return -1;\r
-  }\r
 \r
   mOptions.RecordListFile = (CHAR8 *) malloc (Length);\r
   if (mOptions.RecordListFile == NULL) {\r
@@ -555,12 +531,12 @@ CVfrCompiler::~CVfrCompiler (
   }\r
 \r
   if (mOptions.IncludePaths != NULL) {\r
-    delete mOptions.IncludePaths;\r
+    delete[] mOptions.IncludePaths;\r
     mOptions.IncludePaths = NULL;\r
   }\r
 \r
   if (mOptions.CPreprocessorOptions != NULL) {\r
-    delete mOptions.CPreprocessorOptions;\r
+    delete[] mOptions.CPreprocessorOptions;\r
     mOptions.CPreprocessorOptions = NULL;\r
   }\r
 \r
@@ -642,7 +618,7 @@ CVfrCompiler::PreProcess (
   }\r
 \r
   if ((pVfrFile = fopen (LongFilePath (mOptions.VfrFileName), "r")) == NULL) {\r
-    DebugError (NULL, 0, 0001, "Error opening the input VFR file", mOptions.VfrFileName);\r
+    DebugError (NULL, 0, 0001, "Error opening the input VFR file", "%s", mOptions.VfrFileName);\r
     goto Fail;\r
   }\r
   fclose (pVfrFile);\r
@@ -711,7 +687,7 @@ CVfrCompiler::Compile (
   gCVfrErrorHandle.SetWarningAsError(mOptions.WarningAsError);\r
 \r
   if ((pInFile = fopen (LongFilePath (InFileName), "r")) == NULL) {\r
-    DebugError (NULL, 0, 0001, "Error opening the input file", InFileName);\r
+    DebugError (NULL, 0, 0001, "Error opening the input file", "%s", InFileName);\r
     goto Fail;\r
   }\r
 \r
@@ -727,6 +703,7 @@ CVfrCompiler::Compile (
   }\r
 \r
   fclose (pInFile);\r
+  pInFile = NULL;\r
 \r
   if (gCFormPkg.HavePendingUnassigned () == TRUE) {\r
     gCFormPkg.PendingAssignPrintAll ();\r
@@ -841,7 +818,7 @@ CVfrCompiler::GenBinary (
 \r
   if (mOptions.CreateIfrPkgFile == TRUE) {\r
     if ((pFile = fopen (LongFilePath (mOptions.PkgOutputFileName), "wb")) == NULL) {\r
-      DebugError (NULL, 0, 0001, "Error opening file", mOptions.PkgOutputFileName);\r
+      DebugError (NULL, 0, 0001, "Error opening file", "%s", mOptions.PkgOutputFileName);\r
       goto Fail;\r
     }\r
     if (gCFormPkg.BuildPkg (pFile, &gRBuffer) != VFR_RETURN_SUCCESS) {\r
@@ -884,7 +861,7 @@ CVfrCompiler::GenCFile (
   \r
   if (!mOptions.CreateIfrPkgFile || mOptions.CompatibleMode) {\r
     if ((pFile = fopen (LongFilePath (mOptions.COutputFileName), "w")) == NULL) {\r
-      DebugError (NULL, 0, 0001, "Error opening output C file", mOptions.COutputFileName);\r
+      DebugError (NULL, 0, 0001, "Error opening output C file", "%s", mOptions.COutputFileName);\r
       goto Fail;\r
     }\r
 \r
@@ -925,18 +902,18 @@ CVfrCompiler::GenRecordListFile (
 \r
   InFileName = (mOptions.SkipCPreprocessor == TRUE) ? mOptions.VfrFileName : mOptions.PreprocessorOutputFileName;\r
 \r
-  if (mOptions.CreateRecordListFile == TRUE) {\r
+  if (mOptions.CreateRecordListFile == TRUE && InFileName != NULL && mOptions.RecordListFile != NULL) {\r
     if ((InFileName[0] == '\0') || (mOptions.RecordListFile[0] == '\0')) {\r
       return;\r
     }\r
 \r
     if ((pInFile = fopen (LongFilePath (InFileName), "r")) == NULL) {\r
-      DebugError (NULL, 0, 0001, "Error opening the input VFR preprocessor output file", InFileName);\r
+      DebugError (NULL, 0, 0001, "Error opening the input VFR preprocessor output file", "%s", InFileName);\r
       return;\r
     }\r
 \r
     if ((pOutFile = fopen (LongFilePath (mOptions.RecordListFile), "w")) == NULL) {\r
-      DebugError (NULL, 0, 0001, "Error opening the record list file", mOptions.RecordListFile);\r
+      DebugError (NULL, 0, 0001, "Error opening the record list file", "%s", mOptions.RecordListFile);\r
       goto Err1;\r
     }\r
 \r
@@ -988,11 +965,11 @@ main (
   }\r
 \r
   if (gCBuffer.Buffer != NULL) {\r
-    delete gCBuffer.Buffer;\r
+    delete[] gCBuffer.Buffer;\r
   }\r
   \r
   if (gRBuffer.Buffer != NULL) {\r
-    delete gRBuffer.Buffer;\r
+    delete[] gRBuffer.Buffer;\r
   }\r
 \r
   return GetUtilityStatus ();\r