]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/VfrCompile/VfrFormPkg.cpp
BaseTool/VfrCompile: Support Union type in VFR
[mirror_edk2.git] / BaseTools / Source / C / VfrCompile / VfrFormPkg.cpp
index 0b7b8b1776f594147c04065b36372bed6103848c..2be0c385e31371a28ce542ec78f166907301fff5 100644 (file)
@@ -14,6 +14,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/\r
 \r
 #include "stdio.h"\r
+#include "assert.h"\r
 #include "VfrFormPkg.h"\r
 \r
 /*\r
@@ -55,13 +56,13 @@ SPendingAssign::~SPendingAssign (
   )\r
 {\r
   if (mKey != NULL) {\r
-    delete mKey;\r
+    delete[] mKey;\r
   }\r
   mAddr   = NULL;\r
   mLen    = 0;\r
   mLineNo = 0;\r
   if (mMsg != NULL) {\r
-    delete mMsg;\r
+    delete[] mMsg;\r
   }\r
   mNext   = NULL;\r
 }\r
@@ -112,6 +113,7 @@ CFormPkg::CFormPkg (
   }\r
   BufferStart = new CHAR8[BufferSize];\r
   if (BufferStart == NULL) {\r
+    delete Node;\r
     return;\r
   }\r
   BufferEnd   = BufferStart + BufferSize;\r
@@ -669,6 +671,8 @@ CFormPkg::AdjustDynamicInsertOpcode (
 \r
   InserPositionNode  = GetBinBufferNodeForAddr(InserPositionAddr);\r
   InsertOpcodeNode = GetBinBufferNodeForAddr(InsertOpcodeAddr);\r
+  assert (InserPositionNode != NULL);\r
+  assert (InsertOpcodeNode  != NULL);\r
 \r
   if (InserPositionNode == InsertOpcodeNode) {\r
     //\r
@@ -741,6 +745,8 @@ CFormPkg::AdjustDynamicInsertOpcode (
       // Insert the last restore data node.\r
       //\r
       TmpNode = GetNodeBefore (InsertOpcodeNode);\r
+      assert (TmpNode != NULL);\r
+\r
       if (TmpNode == InserPositionNode) {\r
         NewRestoreNodeBegin->mNext = NewRestoreNodeEnd;\r
       } else {\r
@@ -790,6 +796,8 @@ CFormPkg::AdjustDynamicInsertOpcode (
       mBufferNodeQueueTail = NewLastEndNode;\r
     } else if (mBufferNodeQueueTail->mBufferFree - mBufferNodeQueueTail->mBufferStart == 2) {\r
       TmpNode = GetNodeBefore(mBufferNodeQueueTail);\r
+      assert (TmpNode != NULL);\r
+\r
       TmpNode->mNext = NewRestoreNodeBegin;\r
       if (NewRestoreNodeEnd != NULL) {\r
         NewRestoreNodeEnd->mNext = mBufferNodeQueueTail;\r
@@ -818,10 +826,9 @@ CFormPkg::DeclarePendingQuestion (
   CHAR8          FName[MAX_NAME_LEN];\r
   CHAR8          *SName;\r
   CHAR8          *NewStr;\r
-  UINT32         ShrinkSize;\r
+  UINT32         ShrinkSize = 0;\r
   EFI_VFR_RETURN_CODE  ReturnCode;\r
   EFI_VFR_VARSTORE_TYPE VarStoreType  = EFI_VFR_VARSTORE_INVALID;\r
-  EFI_VARSTORE_ID       VarStoreId    = EFI_VARSTORE_ID_INVALID;\r
 \r
   //\r
   // Declare all questions as Numeric in DisableIf True\r
@@ -891,7 +898,7 @@ CFormPkg::DeclarePendingQuestion (
             strcpy (NewStr, SName);\r
             strcat (NewStr, VarStr + strlen (FName));\r
             ReturnCode = lCVfrVarDataTypeDB.GetDataFieldInfo (NewStr, Info.mInfo.mVarOffset, Info.mVarType, Info.mVarTotalSize);\r
-            delete NewStr;\r
+            delete[] NewStr;\r
           }\r
         } else {\r
           ReturnCode = VFR_RETURN_UNSUPPORTED;\r
@@ -1290,6 +1297,7 @@ CIfrRecordInfoDB::IfrAdjustDynamicOpcodeInRecords (
   SIfrRecord         *pAdjustNode, *pNodeBeforeAdjust;\r
   SIfrRecord         *pNodeBeforeDynamic;\r
 \r
+  pPreNode            = NULL;\r
   pAdjustNode         = NULL;\r
   pNodeBeforeDynamic  = NULL;\r
   OpcodeOffset        = 0;\r
@@ -1314,7 +1322,7 @@ CIfrRecordInfoDB::IfrAdjustDynamicOpcodeInRecords (
   //\r
   // Check the nodes whether exist.\r
   //\r
-  if (pNodeBeforeDynamic == NULL || pAdjustNode == NULL) {\r
+  if (pNodeBeforeDynamic == NULL || pAdjustNode == NULL || pNodeBeforeAdjust == NULL) {\r
     return FALSE;\r
   }\r
 \r
@@ -1357,7 +1365,7 @@ CIfrRecordInfoDB::IfrUpdateRecordInfoForDynamicOpcode (
   // Base on the original offset info to update the record list.\r
   //\r
   if (!IfrAdjustDynamicOpcodeInRecords(CreateOpcodeAfterParsingVfr)) {\r
-    gCVfrErrorHandle.PrintMsg (0, "Error", "Can not find the adjust offset in the record.");\r
+    gCVfrErrorHandle.PrintMsg (0, (CHAR8 *)"Error", (CHAR8 *)"Can not find the adjust offset in the record.");\r
   }\r
 \r
   //\r
@@ -1402,7 +1410,6 @@ CIfrRecordInfoDB::IfrRecordAdjust (
   EFI_QUESTION_ID    QuestionId;\r
   UINT32             StackCount;\r
   UINT32             QuestionScope;\r
-  UINT32             OpcodeOffset;\r
   CHAR8              ErrorMsg[MAX_STRING_LEN] = {0, };\r
   EFI_VFR_RETURN_CODE  Status;\r
 \r
@@ -1838,6 +1845,7 @@ CIfrRecordInfoDB::IfrCreateDefaultForQuestion (
     // Point to the first expression opcode.\r
     //\r
     pSNode = pDefaultNode->mNext;\r
+    pENode = NULL;\r
     ScopeCount++;\r
     //\r
     // Get opcode number behind the EFI_IFR_DEFAULT_2 until reach its END opcode (including the END opcode of EFI_IFR_DEFAULT_2)\r
@@ -1854,6 +1862,10 @@ CIfrRecordInfoDB::IfrCreateDefaultForQuestion (
       pSNode = pSNode->mNext;\r
       OpcodeCount++;\r
     }\r
+\r
+    assert (pSNode);\r
+    assert (pENode);\r
+\r
     //\r
     // Record the offset of node which need to be adjust, will move the new created default opcode to this offset.\r
     //\r
@@ -1875,6 +1887,7 @@ CIfrRecordInfoDB::IfrCreateDefaultForQuestion (
         while (pSNode != NULL && pSNode->mNext != NULL && OpcodeNumber-- != 0) {\r
           pOpHead = (EFI_IFR_OP_HEADER *) pSNode->mIfrBinBuf;\r
           Obj = new CIfrObj (pOpHead->OpCode, NULL, pSNode->mBinBufLen, FALSE);\r
+          assert (Obj != NULL);\r
           Obj->SetLineNo (pSNode->mLineNo);\r
           ObjBinBuf = Obj->GetObjBinAddr();\r
           memcpy (ObjBinBuf, pSNode->mIfrBinBuf, (UINTN)pSNode->mBinBufLen);\r
@@ -2378,6 +2391,8 @@ CIfrObj::CIfrObj (
   mObjBinBuf   = ((DelayEmit == FALSE) && (gCreateOp == TRUE)) ? gCFormPkg.IfrBinBufferGet (mObjBinLen) : new CHAR8[EFI_IFR_MAX_LENGTH];\r
   mRecordIdx   = (gCreateOp == TRUE) ? gCIfrRecordInfoDB.IfrRecordRegister (0xFFFFFFFF, mObjBinBuf, mObjBinLen, mPkgOffset) : EFI_IFR_RECORDINFO_IDX_INVALUD;\r
 \r
+  assert (mObjBinBuf != NULL);\r
+\r
   if (IfrObj != NULL) {\r
     *IfrObj    = mObjBinBuf;\r
   }\r