From fbe12b79aef4c2706e90078cc75b94dcf7926ba8 Mon Sep 17 00:00:00 2001 From: ydong10 Date: Mon, 18 Oct 2010 11:33:26 +0000 Subject: [PATCH] Refine code to make code run more safely. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10955 6f19259b-4bc3-4df7-8a09-765794883524 --- MdeModulePkg/Core/PiSmmCore/Pool.c | 4 ++-- .../Universal/DebugSupportDxe/X64/PlDebugSupportX64.c | 6 +++--- MdeModulePkg/Universal/EbcDxe/EbcExecute.c | 2 +- MdeModulePkg/Universal/EbcDxe/EbcInt.c | 2 +- MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Input.c | 2 ++ .../StatusCodeHandler/RuntimeDxe/SerialStatusCodeWorker.c | 1 + .../StatusCodeHandler/Smm/SerialStatusCodeWorker.c | 1 + 7 files changed, 11 insertions(+), 7 deletions(-) diff --git a/MdeModulePkg/Core/PiSmmCore/Pool.c b/MdeModulePkg/Core/PiSmmCore/Pool.c index 928b6ed2cc..ea28484d68 100644 --- a/MdeModulePkg/Core/PiSmmCore/Pool.c +++ b/MdeModulePkg/Core/PiSmmCore/Pool.c @@ -185,7 +185,7 @@ InternalFreePoolByIndex ( ASSERT (((UINTN)FreePoolHdr & (FreePoolHdr->Header.Size - 1)) == 0); ASSERT (FreePoolHdr->Header.Size >= MIN_POOL_SIZE); - PoolIndex = HighBitSet32 ((UINT32)FreePoolHdr->Header.Size) - MIN_POOL_SHIFT; + PoolIndex = (UINTN) (HighBitSet32 ((UINT32)FreePoolHdr->Header.Size) - MIN_POOL_SHIFT); FreePoolHdr->Header.Available = TRUE; ASSERT (PoolIndex < MAX_POOL_INDEX); InsertHeadList (&mSmmPoolLists[PoolIndex], &FreePoolHdr->Link); @@ -240,7 +240,7 @@ SmmAllocatePool ( } Size = (Size + MIN_POOL_SIZE - 1) >> MIN_POOL_SHIFT; - PoolIndex = HighBitSet32 ((UINT32)Size); + PoolIndex = (UINTN) HighBitSet32 ((UINT32)Size); if ((Size & (Size - 1)) != 0) { PoolIndex++; } diff --git a/MdeModulePkg/Universal/DebugSupportDxe/X64/PlDebugSupportX64.c b/MdeModulePkg/Universal/DebugSupportDxe/X64/PlDebugSupportX64.c index 8e623b9419..fa8869d287 100644 --- a/MdeModulePkg/Universal/DebugSupportDxe/X64/PlDebugSupportX64.c +++ b/MdeModulePkg/Universal/DebugSupportDxe/X64/PlDebugSupportX64.c @@ -36,9 +36,9 @@ GetInterruptHandleFromIdt ( // InterruptHandle 16-31 : OffsetHigh // InterruptHandle 32-63 : OffsetUpper // - ((UINT16 *) &InterruptHandle)[0] = (UINT16) IdtGateDecriptor->Bits.OffsetLow; - ((UINT16 *) &InterruptHandle)[1] = (UINT16) IdtGateDecriptor->Bits.OffsetHigh; - ((UINT32 *) &InterruptHandle)[1] = (UINT32) IdtGateDecriptor->Bits.OffsetUpper; + InterruptHandle = ((UINTN) IdtGateDecriptor->Bits.OffsetLow) | + (((UINTN) IdtGateDecriptor->Bits.OffsetHigh) << 16) | + (((UINTN) IdtGateDecriptor->Bits.OffsetUpper) << 32) ; return InterruptHandle; } diff --git a/MdeModulePkg/Universal/EbcDxe/EbcExecute.c b/MdeModulePkg/Universal/EbcDxe/EbcExecute.c index 48f7dcebdb..0d987043c1 100644 --- a/MdeModulePkg/Universal/EbcDxe/EbcExecute.c +++ b/MdeModulePkg/Universal/EbcDxe/EbcExecute.c @@ -2367,7 +2367,7 @@ ExecuteMOVIn ( // Get the address // Op1 = (UINT64) VmPtr->Gpr[OPERAND1_REGNUM (Operands)] + Index16; - VmWriteMemN (VmPtr, (UINTN) Op1, (INTN) ImmedIndex64); + VmWriteMemN (VmPtr, (UINTN) Op1, (UINTN)(INTN) ImmedIndex64); } // // Advance the instruction pointer diff --git a/MdeModulePkg/Universal/EbcDxe/EbcInt.c b/MdeModulePkg/Universal/EbcDxe/EbcInt.c index dddfd58566..e94ed8e6c3 100644 --- a/MdeModulePkg/Universal/EbcDxe/EbcInt.c +++ b/MdeModulePkg/Universal/EbcDxe/EbcInt.c @@ -747,7 +747,7 @@ EbcDebugSignalException ( // Save the exception in the context passed in // VmPtr->ExceptionFlags |= ExceptionFlags; - VmPtr->LastException = ExceptionType; + VmPtr->LastException = (UINTN) ExceptionType; // // If it's a fatal exception, then flag it in the VM context in case an // attached debugger tries to return from it. diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Input.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Input.c index be87ec5d98..2bb8cd943e 100644 --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Input.c +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Input.c @@ -883,6 +883,8 @@ Ip4AccpetFrame ( goto RESTART; } } + + ASSERT (Packet != NULL); Head = Packet->Ip.Ip4; IP4_GET_CLIP_INFO (Packet)->Status = EFI_SUCCESS; diff --git a/MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/SerialStatusCodeWorker.c b/MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/SerialStatusCodeWorker.c index 6267725751..4a5d65d25e 100644 --- a/MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/SerialStatusCodeWorker.c +++ b/MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/SerialStatusCodeWorker.c @@ -90,6 +90,7 @@ SerialStatusCodeReportWorker ( Value, Instance ); + ASSERT (CharCount > 0); if (CallerId != NULL) { CharCount += AsciiSPrint ( diff --git a/MdeModulePkg/Universal/StatusCodeHandler/Smm/SerialStatusCodeWorker.c b/MdeModulePkg/Universal/StatusCodeHandler/Smm/SerialStatusCodeWorker.c index 27a243be06..868ffad7a3 100644 --- a/MdeModulePkg/Universal/StatusCodeHandler/Smm/SerialStatusCodeWorker.c +++ b/MdeModulePkg/Universal/StatusCodeHandler/Smm/SerialStatusCodeWorker.c @@ -90,6 +90,7 @@ SerialStatusCodeReportWorker ( Value, Instance ); + ASSERT (CharCount > 0); if (CallerId != NULL) { CharCount += AsciiSPrint (