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
This commit is contained in:
ydong10 2010-10-18 11:33:26 +00:00
parent 6517edbe51
commit fbe12b79ae
7 changed files with 11 additions and 7 deletions

View File

@ -185,7 +185,7 @@ InternalFreePoolByIndex (
ASSERT (((UINTN)FreePoolHdr & (FreePoolHdr->Header.Size - 1)) == 0); ASSERT (((UINTN)FreePoolHdr & (FreePoolHdr->Header.Size - 1)) == 0);
ASSERT (FreePoolHdr->Header.Size >= MIN_POOL_SIZE); 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; FreePoolHdr->Header.Available = TRUE;
ASSERT (PoolIndex < MAX_POOL_INDEX); ASSERT (PoolIndex < MAX_POOL_INDEX);
InsertHeadList (&mSmmPoolLists[PoolIndex], &FreePoolHdr->Link); InsertHeadList (&mSmmPoolLists[PoolIndex], &FreePoolHdr->Link);
@ -240,7 +240,7 @@ SmmAllocatePool (
} }
Size = (Size + MIN_POOL_SIZE - 1) >> MIN_POOL_SHIFT; Size = (Size + MIN_POOL_SIZE - 1) >> MIN_POOL_SHIFT;
PoolIndex = HighBitSet32 ((UINT32)Size); PoolIndex = (UINTN) HighBitSet32 ((UINT32)Size);
if ((Size & (Size - 1)) != 0) { if ((Size & (Size - 1)) != 0) {
PoolIndex++; PoolIndex++;
} }

View File

@ -36,9 +36,9 @@ GetInterruptHandleFromIdt (
// InterruptHandle 16-31 : OffsetHigh // InterruptHandle 16-31 : OffsetHigh
// InterruptHandle 32-63 : OffsetUpper // InterruptHandle 32-63 : OffsetUpper
// //
((UINT16 *) &InterruptHandle)[0] = (UINT16) IdtGateDecriptor->Bits.OffsetLow; InterruptHandle = ((UINTN) IdtGateDecriptor->Bits.OffsetLow) |
((UINT16 *) &InterruptHandle)[1] = (UINT16) IdtGateDecriptor->Bits.OffsetHigh; (((UINTN) IdtGateDecriptor->Bits.OffsetHigh) << 16) |
((UINT32 *) &InterruptHandle)[1] = (UINT32) IdtGateDecriptor->Bits.OffsetUpper; (((UINTN) IdtGateDecriptor->Bits.OffsetUpper) << 32) ;
return InterruptHandle; return InterruptHandle;
} }

View File

@ -2367,7 +2367,7 @@ ExecuteMOVIn (
// Get the address // Get the address
// //
Op1 = (UINT64) VmPtr->Gpr[OPERAND1_REGNUM (Operands)] + Index16; 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 // Advance the instruction pointer

View File

@ -747,7 +747,7 @@ EbcDebugSignalException (
// Save the exception in the context passed in // Save the exception in the context passed in
// //
VmPtr->ExceptionFlags |= ExceptionFlags; 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 // If it's a fatal exception, then flag it in the VM context in case an
// attached debugger tries to return from it. // attached debugger tries to return from it.

View File

@ -883,6 +883,8 @@ Ip4AccpetFrame (
goto RESTART; goto RESTART;
} }
} }
ASSERT (Packet != NULL);
Head = Packet->Ip.Ip4; Head = Packet->Ip.Ip4;
IP4_GET_CLIP_INFO (Packet)->Status = EFI_SUCCESS; IP4_GET_CLIP_INFO (Packet)->Status = EFI_SUCCESS;

View File

@ -90,6 +90,7 @@ SerialStatusCodeReportWorker (
Value, Value,
Instance Instance
); );
ASSERT (CharCount > 0);
if (CallerId != NULL) { if (CallerId != NULL) {
CharCount += AsciiSPrint ( CharCount += AsciiSPrint (

View File

@ -90,6 +90,7 @@ SerialStatusCodeReportWorker (
Value, Value,
Instance Instance
); );
ASSERT (CharCount > 0);
if (CallerId != NULL) { if (CallerId != NULL) {
CharCount += AsciiSPrint ( CharCount += AsciiSPrint (