]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/GenFw/Elf32Convert.c
BaseTools: Convert incomplete expression with dangling while()
[mirror_edk2.git] / BaseTools / Source / C / GenFw / Elf32Convert.c
index d115291b062c9f4c3ae5f1876e467aeaa0ebe705..f420bc89da44e1d943a45c5fd8d15ca9bd98181b 100644 (file)
@@ -167,6 +167,10 @@ InitializeElf32 (
   // Create COFF Section offset buffer and zero.\r
   //\r
   mCoffSectionsOffset = (UINT32 *)malloc(mEhdr->e_shnum * sizeof (UINT32));\r
+  if (mCoffSectionsOffset == NULL) {\r
+    Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r
+    return FALSE;\r
+  }\r
   memset(mCoffSectionsOffset, 0, mEhdr->e_shnum * sizeof(UINT32));\r
 \r
   //\r
@@ -314,7 +318,8 @@ GetSymName (
   UINT8* StrtabContents = (UINT8*)mEhdr + StrtabShdr->sh_offset;\r
 \r
   bool foundEnd = false;\r
-  for (UINT32 i = Sym->st_name; (i < StrtabShdr->sh_size) && !foundEnd; i++) {\r
+  UINT32 i;\r
+  for (i = Sym->st_name; (i < StrtabShdr->sh_size) && !foundEnd; i++) {\r
     foundEnd = StrtabContents[i] == 0;\r
   }\r
   assert(foundEnd);\r
@@ -525,6 +530,10 @@ ScanSections32 (
   // Allocate base Coff file.  Will be expanded later for relocations.\r
   //\r
   mCoffFile = (UINT8 *)malloc(mCoffOffset);\r
+  if (mCoffFile == NULL) {\r
+    Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r
+  }\r
+  assert (mCoffFile != NULL);\r
   memset(mCoffFile, 0, mCoffOffset);\r
 \r
   //\r