Add comments and refine code to avoid addition overflow.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7863 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
qhuang8 2009-03-11 13:59:22 +00:00
parent 97ef8cff3e
commit 98a601b177
1 changed files with 5 additions and 1 deletions

View File

@ -161,7 +161,11 @@ PeiAllocatePages (
// Verify that there is sufficient memory to satisfy the allocation
//
RemainingPages = EFI_SIZE_TO_PAGES ((UINTN) (*FreeMemoryTop - *FreeMemoryBottom));
if ((INTN) (RemainingPages - EFI_SIZE_TO_PAGES (sizeof (EFI_HOB_MEMORY_ALLOCATION))) < Pages) {
//
// For page allocation, the overhead sizeof (EFI_HOB_MEMORY_ALLOCATION) needs one extra page.
// So the number of remaining pages needs to be greater than that of the request pages.
//
if (RemainingPages <= Pages) {
DEBUG ((EFI_D_ERROR, "AllocatePages failed: No 0x%lx Pages is available.\n", (UINT64) Pages));
DEBUG ((EFI_D_ERROR, "There is only left 0x%lx pages memory resource to be allocated.\n", (UINT64) RemainingPages));
return EFI_OUT_OF_RESOURCES;