summaryrefslogtreecommitdiff
path: root/ShellPkg
diff options
context:
space:
mode:
authorRuiyu Ni <ruiyu.ni@intel.com>2016-07-12 13:56:04 +0800
committerRuiyu Ni <ruiyu.ni@intel.com>2016-07-18 10:55:14 +0800
commit5945813f69f1d5864bb54982bf59ebd1057c4949 (patch)
tree6bfe2cd90bd412f8e53b22ae1d4175ece94cd837 /ShellPkg
parentaa3276c171e3bd2f29745c4b48589f0faded4322 (diff)
ShellPkg/UefiShellBcfgCommandLib: Handle memory allocation failure
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com> Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Diffstat (limited to 'ShellPkg')
-rw-r--r--ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c49
1 files changed, 25 insertions, 24 deletions
diff --git a/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c b/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c
index bf35a35b98..9baeecc339 100644
--- a/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c
+++ b/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c
@@ -2,7 +2,7 @@
Main file for BCFG command.
(C) Copyright 2014-2015 Hewlett-Packard Development Company, L.P.<BR>
- Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 2016, 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
@@ -553,33 +553,34 @@ BcfgAdd(
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL), gShellBcfgHiiHandle, L"bcfg", OptionStr);
} else {
- NewOrder = AllocateZeroPool((OrderCount+1)*sizeof(NewOrder[0]));
- ASSERT(NewOrder != NULL);
- CopyMem(NewOrder, CurrentOrder, (OrderCount)*sizeof(NewOrder[0]));
+ NewOrder = AllocateZeroPool ((OrderCount + 1) * sizeof (NewOrder[0]));
+ if (NewOrder != NULL) {
+ CopyMem (NewOrder, CurrentOrder, (OrderCount) * sizeof (NewOrder[0]));
- //
- // Insert target into order list
- //
- for (Index=OrderCount; Index > Position; Index--) {
- NewOrder[Index] = NewOrder[Index-1];
- }
+ //
+ // Insert target into order list
+ //
+ for (Index = OrderCount; Index > Position; Index--) {
+ NewOrder[Index] = NewOrder[Index - 1];
+ }
- NewOrder[Position] = (UINT16) TargetLocation;
- Status = gRT->SetVariable (
- Target == BcfgTargetBootOrder?L"BootOrder":L"DriverOrder",
- &gEfiGlobalVariableGuid,
- EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS|EFI_VARIABLE_RUNTIME_ACCESS,
- (OrderCount+1) * sizeof(UINT16),
- NewOrder
- );
+ NewOrder[Position] = (UINT16) TargetLocation;
+ Status = gRT->SetVariable (
+ Target == BcfgTargetBootOrder ? L"BootOrder" : L"DriverOrder",
+ &gEfiGlobalVariableGuid,
+ EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
+ (OrderCount + 1) * sizeof (UINT16),
+ NewOrder
+ );
- FreePool(NewOrder);
+ FreePool (NewOrder);
- if (EFI_ERROR(Status)) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_WRITE_FAIL), gShellBcfgHiiHandle, L"bcfg", Target == BcfgTargetBootOrder?L"BootOrder":L"DriverOrder");
- ShellStatus = SHELL_INVALID_PARAMETER;
- } else {
- Print (L"bcfg: Add %s as %x\n", OptionStr, Position);
+ if (EFI_ERROR (Status)) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_BCFG_WRITE_FAIL), gShellBcfgHiiHandle, L"bcfg", Target == BcfgTargetBootOrder ? L"BootOrder" : L"DriverOrder");
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ } else {
+ Print (L"bcfg: Add %s as %x\n", OptionStr, Position);
+ }
}
}
}