audk/IntelFrameworkModulePkg/Universal/BdsDxe
Hao Wu aa5f60ae41 IntelFrameworkModulePkg: 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: Jeff Fan <jeff.fan@intel.com>
2017-03-06 14:33:22 +08:00
..
BootMaint IntelFrameworkModulePkg: Refine type cast for pointer subtraction 2017-03-06 14:14:46 +08:00
BootMngr IntelFrameworkModulePkg/BdsDxe: rebase to ARRAY_SIZE() 2016-10-27 11:10:55 +02:00
DeviceMngr IntelFrameworkModulePkg: Replace [Ascii|Unicode]ValueToString 2017-03-02 09:57:54 +08:00
Bds.h Report the setting variable failure to platform through the status code when core cannot handle the error. 2014-03-25 02:38:54 +00:00
BdsDxe.inf IntelFrameworkModulePkg: Correct the usage of gPerformanceProtocolGuid in inf 2016-06-12 12:56:23 +08:00
BdsDxe.uni IntelFrameworkModulePkg: Convert all .uni files to utf-8 2015-12-15 04:52:33 +00:00
BdsDxeExtra.uni IntelFrameworkModulePkg: Convert all .uni files to utf-8 2015-12-15 04:52:33 +00:00
BdsEntry.c IntelFrameworkModulePkg: Use EfiEventEmptyFunction from UefiLib 2017-01-20 15:55:32 +08:00
Capsules.c Enable UEFI firmware to support FMP capsule format. 2013-10-15 01:31:49 +00:00
FrontPage.c IntelFrameworkModulePkg: Refine casting expression result to bigger size 2017-03-06 14:33:22 +08:00
FrontPage.h 1. Fix a bug when comparing two timestamp in auth-variable driver. 2012-09-14 02:59:35 +00:00
FrontPageStrings.uni IntelFrameworkModulePkg: Convert all .uni files to utf-8 2015-12-15 04:52:33 +00:00
FrontPageVfr.Vfr EDKII:Display engine should not depend on the framework code 2015-06-09 05:09:50 +00:00
Hotkey.c Correct the convert hex string to decimal value logic. 2014-09-22 05:37:16 +00:00
Hotkey.h Rollback the change to EFI_BOOT_KEY_DATA structure since UEFI Spec adds the clarification that bitfields are ordered such that bit 0 is the least significant bit. 2013-12-18 05:51:22 +00:00
HwErrRecSupport.c Follow UEFI spec, set TimeOut and HwErrRecSupport variable by EFI variable service instead of PcdSet(). 2013-03-05 12:20:53 +00:00
HwErrRecSupport.h Update the copyright notice format 2010-04-23 16:28:26 +00:00
Language.c Add check to avoid null pointer deference. 2014-03-28 02:50:47 +00:00
Language.h Update the copyright notice format 2010-04-23 16:28:26 +00:00
MemoryTest.c IntelFrameworkModulePkg: Replace [Ascii|Unicode]ValueToString 2017-03-02 09:57:54 +08:00
String.c Remove unnecessary mBdsImageHandle. 2010-11-08 06:56:57 +00:00
String.h Clean up the private GUID definition in module Level. 2011-09-18 12:23:27 +00:00
Strings.uni IntelFrameworkModulePkg: Convert all .uni files to utf-8 2015-12-15 04:52:33 +00:00