Acidanthera UEFI Development Kit based on EDK II edk2-stable202311
Go to file
Hao Wu d953f4f1ae IntelFsp2WrapperPkg: Refine casting expression result to bigger size
There are cases that the operands of an expression are all with rank less
than UINT64/INT64 and the result of the expression is explicitly cast to
UINT64/INT64 to fit the target size.

An example will be:
UINT32 a,b;
// a and b can be any unsigned int type with rank less than UINT64, like
// UINT8, UINT16, etc.
UINT64 c;
c = (UINT64) (a + b);

Some static code checkers may warn that the expression result might
overflow within the rank of "int" (integer promotions) and the result is
then cast to a bigger size.

The commit refines codes by the following rules:
1). When the expression is possible to overflow the range of unsigned int/
int:
c = (UINT64)a + b;

2). When the expression will not overflow within the rank of "int", remove
the explicit type casts:
c = a + b;

3). When the expression will be cast to pointer of possible greater size:
UINT32 a,b;
VOID *c;
c = (VOID *)(UINTN)(a + b); --> c = (VOID *)((UINTN)a + b);

4). When one side of a comparison expression contains only operands with
rank less than UINT32:
UINT8 a;
UINT16 b;
UINTN c;
if ((UINTN)(a + b) > c) {...} --> if (((UINT32)a + b) > c) {...}

For rule 4), if we remove the 'UINTN' type cast like:
if (a + b > c) {...}
The VS compiler will complain with warning C4018 (signed/unsigned
mismatch, level 3 warning) due to promoting 'a + b' to type 'int'.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
2017-03-06 14:33:22 +08:00
AppPkg AppPkg: Update email and URL. 2016-10-26 09:34:34 -07:00
ArmPkg ArmPkg/CpuDxe: ignore attribute changes during SyncCacheConfig() 2017-02-28 14:59:50 +00:00
ArmPlatformPkg ArmPlatformPkg/PlatformIntelBdsLib: don't clobber ConSplitter handle 2017-03-03 21:42:38 +00:00
ArmVirtPkg ArmVirtPkg AARCH64: enable NX memory protection for all platforms 2017-03-01 18:35:40 +00:00
BaseTools BaseTools/Source/C/Makefiles: Fix NmakeSubdirs.bat always return 0 2017-03-02 16:43:42 +08:00
BeagleBoardPkg ArmPkg: remove unused PcdArmUncachedMemoryMask PCD 2017-02-27 16:18:29 +00:00
Conf EDK II: Add .gitignore 2014-10-14 16:08:15 +00:00
CorebootModulePkg CorebootPayloadPkg/CbSupportPei: Fix the memory map issue 2016-11-17 14:49:11 -08:00
CorebootPayloadPkg CorebootPayloadPkg: Use EfiEventGroupSignal from UefiLib 2017-01-20 15:55:41 +08:00
CryptoPkg CryptoPkg: Refine type cast for pointer subtraction 2017-03-06 14:14:29 +08:00
DuetPkg DuetPkg: Remove use of IntelFrameworkModulePkg legacy libs 2016-12-02 15:59:19 +00:00
EdkCompatibilityPkg EdkCompatibilityPkg: Fix some typos of "according" 2017-02-08 14:49:21 +08:00
EdkShellBinPkg */Contributions.txt: Update example email address 2015-02-03 17:29:14 +00:00
EdkShellPkg */Contributions.txt: Update example email address 2015-02-03 17:29:14 +00:00
EmbeddedPkg EmbeddedPkg: Remove use of IntelFrameworkModulePkg legacy libs 2016-12-05 15:53:30 +00:00
EmulatorPkg EmulatorPkg: Remove use of IntelFrameworkModulePkg legacy libs 2016-12-02 15:59:19 +00:00
FatBinPkg FatBinPkg: New EnhancedFatDxe binaries for IA32, X64, EBC and IPF 2016-12-19 15:26:52 +08:00
FatPkg FatPkg: Refine casting expression result to bigger size 2017-03-06 14:33:21 +08:00
IntelFrameworkModulePkg IntelFrameworkModulePkg: Refine casting expression result to bigger size 2017-03-06 14:33:22 +08:00
IntelFrameworkPkg IntelFrameworkPkg UefiLib: Make the event empty function public 2017-01-20 15:51:17 +08:00
IntelFsp2Pkg Make [-D Macros] as optional argument for GenCfgOpt 2017-03-01 14:57:58 +08:00
IntelFsp2WrapperPkg IntelFsp2WrapperPkg: Refine casting expression result to bigger size 2017-03-06 14:33:22 +08:00
IntelFspPkg IntelFspPkg: Fix typos in comments 2016-10-24 09:26:28 +08:00
IntelFspWrapperPkg IntelFspWrapperPkg: Fix typos in comments 2016-10-24 09:26:30 +08:00
IntelSiliconPkg IntelSiliconPkg: Fix format issues 2016-12-20 10:51:16 +08:00
MdeModulePkg MdeModulePkg: Refine casting expression result to bigger size 2017-03-06 14:33:20 +08:00
MdePkg MdePkg: Refine casting expression result to bigger size 2017-03-06 14:18:45 +08:00
NetworkPkg NetworkPkg: Refine type cast for pointer subtraction 2017-03-06 14:15:13 +08:00
Nt32Pkg Nt32Pkg: Replace [Ascii|Unicode]ValueToString 2017-03-02 09:58:27 +08:00
Omap35xxPkg ArmPkg: remove unused PcdArmUncachedMemoryMask PCD 2017-02-27 16:18:29 +00:00
OptionRomPkg OptionRomPkg: Fix typos in comments 2016-11-15 11:05:34 +08:00
OvmfPkg OvmfPkg: exclude libssl functionality from OpensslLib if TLS_ENABLE=FALSE 2017-02-25 14:56:53 +01:00
PcAtChipsetPkg PcAtChipsetPkg: Fix typing errors 2017-01-20 08:50:09 +08:00
PerformancePkg PerformancePkg: Link DxeSmmPerformanceLib to make DP command generic 2017-03-02 09:12:00 +08:00
QuarkPlatformPkg QuarkPlatformPkg/Tpm12DeviceLibAtmelI2c: Fix GCC build issues 2017-01-11 11:11:30 -08:00
QuarkSocPkg QuarkSocPkg: Remove use of IntelFrameworkModulePkg legacy libs 2016-12-02 15:59:19 +00:00
SecurityPkg SecurityPkg: Refine type cast for pointer subtraction 2017-03-06 14:15:36 +08:00
ShellBinPkg ShellBinPkg: New Shell binaries for IA32 and X64 2016-12-19 15:27:38 +08:00
ShellPkg ShellPkg: Refine type cast for pointer subtraction 2017-03-06 14:16:00 +08:00
SignedCapsulePkg SignedCapsulePkg: Replace [Ascii|Unicode]ValueToString 2017-03-02 09:58:50 +08:00
SourceLevelDebugPkg SourceLevelDebugPkg: Avoid to re-init IDT table again at SMI entry 2016-11-30 14:34:45 +08:00
StdLib StdLib/LibC ARM AARCH64: do not redefine compiler intrinsics 2016-08-09 10:10:12 +02:00
StdLibPrivateInternalFiles StdLib: Clarify and improve comments. 2016-01-06 00:31:42 +00:00
UefiCpuPkg UefiCpuPkg/PiSmmCpuDxeSmm: Add support for PCD PcdPteMemoryEncryptionAddressOrMask 2017-03-01 12:53:03 +08:00
UnixPkg UnixPkg: Remove UnixPkg files (It is replaced by EmulatorPkg) 2013-07-29 21:09:55 +00:00
Vlv2DeviceRefCodePkg Vlv2DeviceRefCodePkg: Fixed thermal issue. 2017-02-08 15:32:39 +08:00
Vlv2TbltDevicePkg Vlv2TbltDevicePkg/BootScriptSaveDxe: save 64-bit LoopTimes 2017-01-03 12:23:41 +01:00
.gitignore EDK II: Add .gitignore 2014-10-14 16:08:15 +00:00
BuildNotes2.txt BaseTools: Updated BuildNotes URLs 2016-03-25 09:46:44 +08:00
Edk2Setup.bat Edk2Setup.bat: Fix build errors from VS tools PREFIX ENV missing 2016-11-05 09:10:58 +08:00
Maintainers.txt Maintainers.txt: Change maintainer of VLV2 packages. 2016-10-27 21:08:23 +08:00
edksetup.bat edksetup.bat: make sure BASE_TOOLS_PATH be set correctly 2016-10-26 13:45:45 +08:00
edksetup.sh edksetup.sh, BaseTools/BuildEnv: add --reconfig support 2016-10-24 13:53:16 +01:00