summaryrefslogtreecommitdiffstats
path: root/UefiCpuPkg
diff options
context:
space:
mode:
authorMarvin H?user <Marvin.Haeuser@outlook.com>2018-10-28 16:51:22 +0800
committerEric Dong <eric.dong@intel.com>2018-10-30 10:21:29 +0800
commit37fba7c2762e114a280e3b361b53ded034aac7e3 (patch)
tree8c4c650602a63beebaa6a92bd6f34e88522cb27c /UefiCpuPkg
parent61a62fc2587ae4d01718124f28e1ea0e60375902 (diff)
downloadedk2-37fba7c2762e114a280e3b361b53ded034aac7e3.tar.gz
edk2-37fba7c2762e114a280e3b361b53ded034aac7e3.tar.bz2
edk2-37fba7c2762e114a280e3b361b53ded034aac7e3.zip
UefiCpuPkg/MpInitLib: Fix ASSERT for success.
Index is initialized to MAX_UINT16 as default failure value, which is what the ASSERT is supposed to test for. The ASSERT condition however can never return FALSE for INT16 != int, as due to Integer Promotion[1], Index is converted to int, which can never result in -1. Furthermore, Index is used as a for loop index variable inbetween its initialization and the ASSERT, so the value is unconditionally overwritten too. Fix the ASSERT check to compare Index to its upper boundary, which it will be equal to if the loop was not broken out of on success. [1] ISO/IEC 9899:2011, 6.5.9.4 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Marvin Haeuser <Marvin.Haeuser@outlook.com> Reviewed-by: Eric Dong <eric.dong@intel.com>
Diffstat (limited to 'UefiCpuPkg')
-rw-r--r--UefiCpuPkg/Library/MpInitLib/DxeMpLib.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
index c17daa0fc0..b2307cbb61 100644
--- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
@@ -236,7 +236,6 @@ GetProtectedModeCS (
UINTN GdtEntryCount;
UINT16 Index;
- Index = (UINT16) -1;
AsmReadGdtr (&GdtrDesc);
GdtEntryCount = (GdtrDesc.Limit + 1) / sizeof (IA32_SEGMENT_DESCRIPTOR);
GdtEntry = (IA32_SEGMENT_DESCRIPTOR *) GdtrDesc.Base;
@@ -248,7 +247,7 @@ GetProtectedModeCS (
}
GdtEntry++;
}
- ASSERT (Index != -1);
+ ASSERT (Index != GdtEntryCount);
return Index * 8;
}