audk/MdeModulePkg/Library
Hao Wu 16f6922709 MdeModulePkg: 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: Feng Tian <feng.tian@intel.com>
2017-03-06 14:33:20 +08:00
..
AuthVariableLibNull MdeModulePkg: Convert all .uni files to utf-8 2015-12-15 04:56:23 +00:00
BaseIpmiLibNull MdeModulePkg: Add the missing Library uni files of Ipmi instances 2015-12-24 02:28:45 +00:00
BasePlatformHookLibNull MdeModulePkg: Convert all .uni files to utf-8 2015-12-15 04:56:23 +00:00
BaseResetSystemLibNull MdeModulePkg/BaseResetSystemLibNull: Implement ResetPlatformSpecific 2016-09-02 10:07:14 +08:00
BaseSerialPortLib16550 MdeModulePkg BaseSerialPortLib: Fix VS2010 build error 2016-01-11 00:34:15 +00:00
BaseSortLib MdeModulePkg: Convert all .uni files to utf-8 2015-12-15 04:56:23 +00:00
BootLogoLib MdeModulePkg/BootLogoLib: Remove invalid if judgments 2016-11-11 12:55:46 +08:00
BootMaintenanceManagerUiLib MdeModulePkg: Replace [Ascii|Unicode]ValueToString 2017-03-02 09:58:11 +08:00
BootManagerUiLib MdeModulePkg/BootManagerUiLib: rebase to ARRAY_SIZE() 2016-10-27 11:10:56 +02:00
CpuExceptionHandlerLibNull MdeModulePkg/CpuExceptionHanderLibNull: RegisterCpuInterruptHandler() 2016-11-18 09:43:51 +08:00
CustomizedDisplayLib MdeModulePkg/Library: Fix typos in comments and variables 2016-10-27 09:11:19 +08:00
DebugAgentLibNull MdeModulePkg/Library: Fix typos in comments and variables 2016-10-27 09:11:19 +08:00
DeviceManagerUiLib MdeModulePkg: Replace [Ascii|Unicode]ValueToString 2017-03-02 09:58:11 +08:00
DxeCapsuleLibFmp MdeModulePkg: Refine casting expression result to bigger size 2017-03-06 14:33:20 +08:00
DxeCapsuleLibNull MdeModulePkg/DxeCapsuleLibNull: Add ProcessCapsules() interface. 2016-11-08 22:36:58 +08:00
DxeCoreMemoryAllocationLib MdeModulePkg: Refine casting expression result to bigger size 2017-03-06 14:33:20 +08:00
DxeCorePerformanceLib MdeModulePkg PerformanceLib: Fix GCC build failure caused by cfb0aba 2017-02-24 16:33:26 +08:00
DxeCrc32GuidedSectionExtractLib MdeModulePkg/Library: Fix typos in comments and variables 2016-10-27 09:11:19 +08:00
DxeDebugPrintErrorLevelLib MdeModulePkg/Library: Fix typos in comments and variables 2016-10-27 09:11:19 +08:00
DxeDpcLib MdeModulePkg: Convert all .uni files to utf-8 2015-12-15 04:56:23 +00:00
DxeFileExplorerProtocol MdeModulePkg DxeFileExplorerProtocol: Change file format which has mixed file format. 2015-12-16 03:20:21 +00:00
DxeHttpLib MdeModulePkg/DxeHttpLib: Correct the return status for the HTTP Port/ContentLength 2017-02-09 08:33:21 +08:00
DxeIpIoLib MdeModulePkg: Update IP4 stack drivers for classless address unicast check. 2016-10-28 14:20:10 +08:00
DxeIpmiLibIpmiProtocol MdeModulePkg: Add the missing Library uni files of Ipmi instances 2015-12-24 02:28:45 +00:00
DxeNetLib MdeModulePkg: Refine casting expression result to bigger size 2017-03-06 14:33:20 +08:00
DxePerformanceLib MdeModulePkg: Update PerformanceLib instances not to check Identifier. 2016-04-11 16:20:28 +08:00
DxePrintLibPrint2Protocol MdeModulePkg: Refine type cast for pointer subtraction 2017-03-06 14:14:09 +08:00
DxeReportStatusCodeLib MdeModulePkg: Convert all .uni files to utf-8 2015-12-15 04:56:23 +00:00
DxeSecurityManagementLib MdeModulePkg: Convert all .uni files to utf-8 2015-12-15 04:56:23 +00:00
DxeSmmPerformanceLib MdeModulePkg DxeSmmPerformanceLib: Add missing UefiLib in *.inf at de2459d 2016-06-29 12:54:53 +08:00
DxeTcpIoLib MdeModulePkg: Convert all .uni files to utf-8 2015-12-15 04:56:23 +00:00
DxeUdpIoLib MdeModulePkg: DxeUdpIoLib: fix non-empty payload path in UDP reception 2016-04-04 13:53:12 +02:00
FileExplorerLib MdeModulePkg: Refine type cast for pointer subtraction 2017-03-06 14:14:09 +08:00
FmpAuthenticationLibNull MdeModulePkg/FmpAuthenticationLibNull: Add NULL instance FMP. 2016-11-08 22:36:55 +08:00
FrameBufferBltLib MdeModulePkg/FrameBufferBltLib: Use dynamic allocated line buffer 2017-01-24 15:06:39 +08:00
LockBoxNullLib MdeModulePkg: Convert all .uni files to utf-8 2015-12-15 04:56:23 +00:00
LzmaCustomDecompressLib MdeModulePkg LzmaDecompressLib: Update LZMA to new 16.04 version 2016-11-03 10:21:19 +08:00
NonDiscoverableDeviceRegistrationLib MdeModulePkg/NonDiscoverable: Compare SIZE_4GB with address type 2017-01-12 21:26:30 +08:00
OemHookStatusCodeLibNull MdeModulePkg: Convert all .uni files to utf-8 2015-12-15 04:56:23 +00:00
PciHostBridgeLibNull MdeModulePkg/PciHostBridgeLib: Correct the function header comments 2016-03-03 18:24:25 +01:00
PeiCrc32GuidedSectionExtractLib MdeModulePkg/Library: Fix typos in comments and variables 2016-10-27 09:11:19 +08:00
PeiDebugPrintHobLib MdeModulePkg: Convert all .uni files to utf-8 2015-12-15 04:56:23 +00:00
PeiDxeDebugLibReportStatusCode MdeModulePkg: Convert all .uni files to utf-8 2015-12-15 04:56:23 +00:00
PeiIpmiLibIpmiPpi MdeModulePkg: Add the missing Library uni files of Ipmi instances 2015-12-24 02:28:45 +00:00
PeiPerformanceLib MdeModulePkg: Update PerformanceLib instances not to check Identifier. 2016-04-11 16:20:28 +08:00
PeiRecoveryLibNull MdeModulePkg: Convert all .uni files to utf-8 2015-12-15 04:56:23 +00:00
PeiReportStatusCodeLib MdeModulePkg: Convert all .uni files to utf-8 2015-12-15 04:56:23 +00:00
PeiS3LibNull MdeModulePkg: Convert all .uni files to utf-8 2015-12-15 04:56:23 +00:00
PiDxeS3BootScriptLib MdeModulePkg: Refine casting expression result to bigger size 2017-03-06 14:33:20 +08:00
PiSmmCoreMemoryAllocationLib MdeModulePkg: Refine casting expression result to bigger size 2017-03-06 14:33:20 +08:00
PiSmmCoreSmmServicesTableLib MdeModulePkg: Convert all .uni files to utf-8 2015-12-15 04:56:23 +00:00
PlatformBootManagerLibNull MdeModulePkg: Convert all .uni files to utf-8 2015-12-15 04:56:23 +00:00
PlatformHookLibSerialPortPpi MdeModulePkg: Correct PlatformHookLibSerialPortPpi module type. 2016-04-25 13:17:05 +08:00
PlatformVarCleanupLib MdeModulePkg/Library: Fix typos in comments and variables 2016-10-27 09:11:19 +08:00
RuntimeDxeReportStatusCodeLib MdeModulePkg: Convert all .uni files to utf-8 2015-12-15 04:56:23 +00:00
SmmCorePerformanceLib MdeModulePkg PerformanceLib: Fix GCC build failure caused by cfb0aba 2017-02-24 16:33:26 +08:00
SmmCorePlatformHookLibNull MdeModulePkg: Convert all .uni files to utf-8 2015-12-15 04:56:23 +00:00
SmmIpmiLibSmmIpmiProtocol MdeModulePkg: Add the missing Library uni files of Ipmi instances 2015-12-24 02:28:45 +00:00
SmmLockBoxLib MdeModulePkg SmmLockBoxSmmLib: Add DESTRUCTOR SmmLockBoxSmmDestructor 2016-06-07 10:01:09 +08:00
SmmMemoryAllocationProfileLib MdeModulePkg: Refine casting expression result to bigger size 2017-03-06 14:33:20 +08:00
SmmPerformanceLib MdeModulePkg: Update PerformanceLib instances not to check Identifier. 2016-04-11 16:20:28 +08:00
SmmReportStatusCodeLib MdeModulePkg: Convert all .uni files to utf-8 2015-12-15 04:56:23 +00:00
SmmSmiHandlerProfileLib MdeModulePkg: Fix coding style issues 2017-02-28 16:45:18 +08:00
TpmMeasurementLibNull MdeModulePkg: Convert all .uni files to utf-8 2015-12-15 04:56:23 +00:00
UefiBootManagerLib MdeModulePkg: Refine casting expression result to bigger size 2017-03-06 14:33:20 +08:00
UefiHiiLib MdeModulePkg: Refine casting expression result to bigger size 2017-03-06 14:33:20 +08:00
UefiHiiServicesLib MdeModulePkg: Convert all .uni files to utf-8 2015-12-15 04:56:23 +00:00
UefiMemoryAllocationProfileLib MdeModulePkg: Refine casting expression result to bigger size 2017-03-06 14:33:20 +08:00
UefiSortLib MdeModulePkg: Convert all .uni files to utf-8 2015-12-15 04:56:23 +00:00
VarCheckHiiLib MdeModulePkg: Refine casting expression result to bigger size 2017-03-06 14:33:20 +08:00
VarCheckLib MdeModulePkg VarCheck: #### in L"Boot####" are upper case hex 2016-08-31 15:23:42 +08:00
VarCheckPcdLib MdeModulePkg: Convert all .uni files to utf-8 2015-12-15 04:56:23 +00:00
VarCheckUefiLib MdeModulePkg VarCheck: #### in L"Boot####" are upper case hex 2016-08-31 15:23:42 +08:00