Refine code to make it more safely.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Feng Tian <feng.tian@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15598 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Eric Dong 2014-06-26 03:24:25 +00:00 committed by ydong10
parent d0f65b21c5
commit 523f48e771
21 changed files with 55 additions and 21 deletions

View File

@ -3,7 +3,7 @@ PEIM to produce gEfiPeiVirtualBlockIoPpiGuid PPI for ATA controllers in the plat
This PPI canl be consumed by PEIM which produce gEfiPeiDeviceRecoveryModulePpiGuid
for Atapi CD ROM device.
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions
@ -1442,6 +1442,7 @@ Inquiry (
// prepare command packet for the ATAPI Inquiry Packet Command.
//
ZeroMem (&Packet, sizeof (ATAPI_PACKET_COMMAND));
ZeroMem (&Idata, sizeof (ATAPI_INQUIRY_DATA));
Packet.Inquiry.opcode = ATA_CMD_INQUIRY;
Packet.Inquiry.page_code = 0;

View File

@ -2,7 +2,7 @@
PEIM to produce gPeiUsbHostControllerPpiGuid based on gPeiUsbControllerPpiGuid
which is used to enable recovery function from USB Drivers.
Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved. <BR>
Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved. <BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions
@ -1047,11 +1047,13 @@ CreateFrameList (
if (Status != EFI_SUCCESS) {
return EFI_OUT_OF_RESOURCES;
}
ASSERT (UhcDev->ConfigQH != NULL);
Status = CreateQH(UhcDev, &UhcDev->BulkQH);
if (Status != EFI_SUCCESS) {
return EFI_OUT_OF_RESOURCES;
}
ASSERT (UhcDev->BulkQH != NULL);
//
//Set the corresponding QH pointer

View File

@ -1,7 +1,7 @@
/** @file
Implements functions to read firmware file
Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -447,6 +447,7 @@ FvReadFileSection (
if (EFI_ERROR (Status)) {
return Status;
}
ASSERT (FileBuffer != NULL);
//
// Check to see that the file actually HAS sections before we go any further.

View File

@ -5,7 +5,7 @@
if a driver can be scheduled for execution. The criteria for
schedulability is that the dependency expression is satisfied.
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -106,7 +106,7 @@ PeimDispatchReadiness (
Iterator = DependencyExpression;
StackPtr = &EvalStack[0];
StackPtr = EvalStack;
while (TRUE) {

View File

@ -388,7 +388,7 @@ SetPassword (
//
// Get user input password
//
Password = &PrivateData->Configuration.WhatIsThePassword2[0];
Password = PrivateData->Configuration.WhatIsThePassword2;
PasswordSize = sizeof (PrivateData->Configuration.WhatIsThePassword2);
ZeroMem (Password, PasswordSize);

View File

@ -4339,6 +4339,7 @@ HiiConfigRoutingRouteConfig (
);
}
if (EFI_ERROR (Status)) {
ASSERT (AccessProgress != NULL);
//
// AccessProgress indicates the parsing progress on <ConfigResp>.
// Map it to the progress on <MultiConfigResp> then return it.

View File

@ -1,7 +1,7 @@
/** @file
Implementation for EFI_HII_DATABASE_PROTOCOL.
Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -2419,6 +2419,7 @@ AddPackages (
//
StringPkgIsAdd = FALSE;
FontPackage = NULL;
StringPackage = NULL;
//
// Process the package list header
@ -2505,6 +2506,7 @@ AddPackages (
if (EFI_ERROR (Status)) {
return Status;
}
ASSERT (StringPackage != NULL);
Status = InvokeRegisteredFunction (
Private,
NotifyType,

View File

@ -2,7 +2,7 @@
Implementation for EFI_HII_FONT_PROTOCOL.
Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -1040,8 +1040,12 @@ IsSystemFontInfo (
return TRUE;
}
SystemDefault = NULL;
DefaultLen = 0;
Status = GetSystemFont (Private, &SystemDefault, &DefaultLen);
ASSERT_EFI_ERROR (Status);
ASSERT ((SystemDefault != NULL) && (DefaultLen != 0));
//
// Record the system default info.
@ -1687,6 +1691,7 @@ HiiStringToImage (
SysFontFlag = IsSystemFontInfo (Private, (EFI_FONT_DISPLAY_INFO *) StringInfo, &SystemDefault, NULL);
if (SysFontFlag) {
ASSERT (SystemDefault != NULL);
FontInfo = NULL;
Height = SystemDefault->FontInfo.FontSize;
BaseLine = SystemDefault->FontInfo.FontSize;
@ -2580,6 +2585,7 @@ HiiGetGlyph (
Foreground = StringInfoOut->ForegroundColor;
Background = StringInfoOut->BackgroundColor;
} else {
ASSERT (SystemDefault != NULL);
Foreground = SystemDefault->ForegroundColor;
Background = SystemDefault->BackgroundColor;
}
@ -2723,6 +2729,7 @@ HiiGetFontInfo (
return EFI_INVALID_PARAMETER;
}
StringInfoOutLen = 0;
FontInfo = NULL;
SystemDefault = NULL;
LocalFontHandle = NULL;

View File

@ -2,7 +2,7 @@
Implementation for EFI_HII_IMAGE_PROTOCOL.
Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -1237,6 +1237,7 @@ HiiDrawImage (
return EFI_INVALID_PARAMETER;
}
FontInfo = NULL;
ImageIn = (EFI_IMAGE_INPUT *) Image;
//
@ -1383,6 +1384,7 @@ HiiDrawImage (
FreePool (ImageOut);
return Status;
}
ASSERT (FontInfo != NULL);
for (Index = 0; Index < Width * Height; Index++) {
BltBuffer[Index] = FontInfo->BackgroundColor;
}

View File

@ -1,7 +1,7 @@
/** @file
EFI DHCP protocol implementation.
Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -404,6 +404,7 @@ DhcpLeaseAcquired (
if (DhcpSb->Netmask == 0) {
Class = NetGetIpClass (DhcpSb->ClientAddr);
ASSERT (Class < IP4_ADDR_CLASSE);
DhcpSb->Netmask = gIp4AllMasks[Class << 3];
}

View File

@ -227,6 +227,7 @@ IScsiUpdateDeviceList (
);
if (Status == EFI_BUFFER_TOO_SMALL) {
DeviceList = (ISCSI_DEVICE_LIST *) AllocatePool (DataSize);
ASSERT (DeviceList != NULL);
gRT->GetVariable (
L"iSCSIDeviceList",
@ -291,6 +292,7 @@ IScsiUpdateDeviceList (
//
DeviceListSize = sizeof (ISCSI_DEVICE_LIST) + (NumHandles - 1) * sizeof (ISCSI_MAC_INFO);
DeviceList = (ISCSI_DEVICE_LIST *) AllocatePool (DeviceListSize);
ASSERT (DeviceList != NULL);
DeviceList->NumDevice = (UINT8) NumHandles;
for (Index = 0; Index < NumHandles; Index++) {

View File

@ -219,6 +219,7 @@ IScsiLunToUnicodeStr (
TempStr += StrLen (TempStr);
}
ASSERT (StrLen(Str) >= 1);
Str[StrLen (Str) - 1] = 0;
for (Index = StrLen (Str) - 1; Index > 1; Index = Index - 2) {

View File

@ -1,7 +1,7 @@
/** @file
Implement IP4 pesudo interface.
Copyright (c) 2005 - 2013, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -582,6 +582,7 @@ Ip4SetAddress (
Type = NetGetIpClass (IpAddr);
Len = NetGetMaskLength (SubnetMask);
ASSERT (Len >= 1);
Netmask = gIp4AllMasks[MIN ((Len - 1), Type << 3)];
Interface->NetBrdcast = (IpAddr | ~Netmask);

View File

@ -1,7 +1,7 @@
/** @file
Routines to process Rrq (download).
Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -704,6 +704,7 @@ Mtftp4RrqInput (
} else {
Packet = (EFI_MTFTP4_PACKET *) NetbufGetByte (UdpPacket, 0, NULL);
ASSERT (Packet != NULL);
}
Opcode = NTOHS (Packet->OpCode);

View File

@ -1,7 +1,7 @@
/** @file
Routines to process Wrq (upload).
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -398,6 +398,7 @@ Mtftp4WrqInput (
} else {
Packet = (EFI_MTFTP4_PACKET *) NetbufGetByte (UdpPacket, 0, NULL);
ASSERT (Packet != NULL);
}
Opcode = NTOHS (Packet->OpCode);

View File

@ -1,7 +1,7 @@
/** @file
Implementation of driver entry point and driver binding protocol.
Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed
and made available under the terms and conditions of the BSD License which
accompanies this distribution. The full text of the license may be found at
@ -545,8 +545,8 @@ SimpleNetworkDriverStart (
// the IO BAR. Save the index of the BAR into the adapter info structure.
// for regular 32bit BARs, 0 is memory mapped, 1 is io mapped
//
ConfigHeader = (PCI_TYPE00 *) &ConfigInfo.Config.Byte[0];
TempBar = (UINT32 *) &ConfigHeader->Device.Bar[0];
ConfigHeader = (PCI_TYPE00 *) ConfigInfo.Config.Byte;
TempBar = (UINT32 *) ConfigHeader->Device.Bar;
for (BarIndex = 0; BarIndex <= 5; BarIndex++) {
if ((*TempBar & PCI_BAR_MEM_MASK) == PCI_BAR_MEM_64BIT) {
//

View File

@ -477,6 +477,7 @@ PxeBcCheckSelectedOffer (
//
Status = EFI_NO_RESPONSE;
ASSERT (Private->NumOffers < PXEBC_MAX_OFFER_NUM);
for (Index = 0; Index < Private->NumOffers; Index++) {
Offer = &Private->Dhcp4Offers[Index].Packet.Offer;

View File

@ -123,10 +123,11 @@ DevicePathToStr (
TRUE
);
if (Text == NULL) {
return AllocateCopyPool (sizeof (L"?"), L"?");
} else {
return Text;
Text = AllocateCopyPool (sizeof (L"?"), L"?");
ASSERT (Text != NULL);
}
return Text;
}
/**

View File

@ -1,7 +1,7 @@
/** @file
Parser for IFR binary encoding.
Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -663,6 +663,7 @@ InitializeRequestElement (
ASSERT (ConfigInfo != NULL);
ConfigInfo->Signature = FORM_BROWSER_CONFIG_REQUEST_SIGNATURE;
ConfigInfo->ConfigRequest = AllocateCopyPool (StrSize (Storage->ConfigHdr), Storage->ConfigHdr);
ASSERT (ConfigInfo->ConfigRequest != NULL);
ConfigInfo->SpareStrLen = 0;
ConfigInfo->Storage = Storage;
InsertTailList(&Form->ConfigRequestHead, &ConfigInfo->Link);
@ -2327,6 +2328,7 @@ ParseOpCodes (
break;
case EFI_IFR_ONE_OF_OPTION_OP:
ASSERT (CurrentOption != NULL);
ImageId = &CurrentOption->ImageId;
break;

View File

@ -397,8 +397,11 @@ UpdateHotkeyList (
HotKey = BROWSER_HOT_KEY_FROM_LINK (Link);
CopyKey = AllocateCopyPool(sizeof (BROWSER_HOT_KEY), HotKey);
ASSERT (CopyKey != NULL);
CopyKey->KeyData = AllocateCopyPool(sizeof (EFI_INPUT_KEY), HotKey->KeyData);
ASSERT (CopyKey->KeyData != NULL);
CopyKey->HelpString = AllocateCopyPool(StrSize (HotKey->HelpString), HotKey->HelpString);
ASSERT (CopyKey->HelpString != NULL);
InsertTailList(&gDisplayFormData.HotKeyListHead, &CopyKey->Link);
@ -1977,6 +1980,7 @@ ProcessCallBackFunction (
if (Action == EFI_BROWSER_ACTION_CHANGING) {
if (HiiValue->Type == EFI_IFR_TYPE_BUFFER) {
BackUpBuffer = AllocateCopyPool(Statement->StorageWidth + sizeof(CHAR16), Statement->BufferValue);
ASSERT (BackUpBuffer != NULL);
} else {
CopyMem (&BackUpValue, &HiiValue->Value, sizeof (EFI_IFR_TYPE_VALUE));
}

View File

@ -4060,8 +4060,11 @@ GetDefaultForFormset (
}
TmpNode = AllocateCopyPool (sizeof (NAME_VALUE_NODE), Node);
ASSERT (TmpNode != NULL);
TmpNode->Name = AllocateCopyPool (StrSize(Node->Name) * sizeof (CHAR16), Node->Name);
ASSERT (TmpNode->Name != NULL);
TmpNode->EditValue = AllocateCopyPool (StrSize(Node->EditValue) * sizeof (CHAR16), Node->EditValue);
ASSERT (TmpNode->EditValue != NULL);
InsertTailList(&BackUpList, &TmpNode->Link);
}