]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/DxeMemoryAllocationLib/MemoryAllocationLib.c
MemoryAllocationLib: For boundary case: “AllocationSize + OverAllocationSize >= 4G”
[mirror_edk2.git] / MdePkg / Library / DxeMemoryAllocationLib / MemoryAllocationLib.c
index ef643eed4296d2252506098a5bc5b18922425dc6..088a10bb5623f5f27bb67084f979226909a91c18 100644 (file)
@@ -168,13 +168,11 @@ InternalAllocateAlignedPages (
     //\r
     AlignmentMask  = Alignment - 1;\r
     RealPages      = Pages + EFI_SIZE_TO_PAGES (Alignment);\r
-    if (RealPages <= Pages) {\r
-      //\r
-      // This extra checking is to make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow. \r
-      //\r
-      return NULL;\r
-    }\r
-\r
+    //\r
+    // Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow.\r
+    //\r
+    ASSERT (RealPages > Pages);\r
\r
     Status         = gBS->AllocatePages (AllocateAnyPages, MemoryType, RealPages, &Memory);\r
     if (EFI_ERROR (Status)) {\r
       return NULL;\r
@@ -601,12 +599,11 @@ InternalAllocateAlignedPool (
   //\r
   OverAllocationSize  = sizeof (RawAddress) + AlignmentMask;\r
   RealAllocationSize  = AllocationSize + OverAllocationSize;\r
-  if (RealAllocationSize <= AllocationSize ) {\r
-    //\r
-    // This extra checking is to make sure that AllocationSize plus OverAllocationSize does not overflow. \r
-    //\r
-    return NULL;\r
-  }\r
+  //\r
+  // Make sure that AllocationSize plus OverAllocationSize does not overflow. \r
+  //\r
+  ASSERT (RealAllocationSize > AllocationSize); \r
+\r
   RawAddress = InternalAllocatePool (PoolType, RealAllocationSize);\r
   if (RawAddress == NULL) {\r
     return NULL;\r