audk/MdeModulePkg/Include/Library
Hao Wu 809e2bbf41 MdeModulePkg: Refine type cast for pointer subtraction
For pointer subtraction, the result is of type "ptrdiff_t". According to
the C11 standard (Committee Draft - April 12, 2011):

"When two pointers are subtracted, both shall point to elements of the
same array object, or one past the last element of the array object; the
result is the difference of the subscripts of the two array elements. The
size of the result is implementation-defined, and its type (a signed
integer type) is ptrdiff_t defined in the <stddef.h> header. If the result
is not representable in an object of that type, the behavior is
undefined."

In our codes, there are cases that the pointer subtraction is not
performed by pointers to elements of the same array object. This might
lead to potential issues, since the behavior is undefined according to C11
standard.

Also, since the size of type "ptrdiff_t" is implementation-defined. Some
static code checkers may warn that the pointer subtraction might underflow
first and then being cast to a bigger size. For example:

UINT8  *Ptr1, *Ptr2;
UINTN  PtrDiff;
...
PtrDiff = (UINTN) (Ptr1 - Ptr2);

The commit will refine the pointer subtraction expressions by casting each
pointer to UINTN first and then perform the subtraction:

PtrDiff = (UINTN) Ptr1 - (UINTN) Ptr2;

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Feng Tian <feng.tian@intel.com>
2017-03-06 14:14:09 +08:00
..
AuthVariableLib.h MdeModulePkg VariableDxe: Correct address pointers from AuthVariableLib 2015-07-26 08:03:50 +00:00
BootLogoLib.h MdeModulePkg/BootLogoLib&PlatformLogo: Use HII data types in parameters 2016-09-28 16:22:20 +08:00
CapsuleLib.h MdeModulePkg/CapsuleLib: Add ProcessCapsules() API. 2016-11-08 22:36:50 +08:00
CpuExceptionHandlerLib.h
CustomizedDisplayLib.h MdeModulePkg/Include: Fix typos in comments 2016-10-27 09:11:18 +08:00
DebugAgentLib.h MdeModulePkg/Include: Fix typos in comments 2016-10-27 09:11:18 +08:00
DpcLib.h
FileExplorerLib.h MdeModulePkg/FileExplorerLib.h: Remove the redefinition of typedefs 2016-03-24 09:00:53 +08:00
FmpAuthenticationLib.h MdeModulePkg/Include: Add FmpAuthenticationLib header. 2016-11-08 22:36:48 +08:00
FrameBufferBltLib.h MdeModulePkg: Add FrameBufferBltLib library class 2016-10-12 10:42:15 +08:00
HiiLib.h MdeModulePkg/Include: Fix typos in comments 2016-10-27 09:11:18 +08:00
HttpLib.h MdeModulePkg:DxeHttpLib: Update to DxeHttpLib API 2016-04-27 10:43:08 +08:00
IpIoLib.h MdeModulePkg: Update IP4 stack drivers for classless address unicast check. 2016-10-28 14:20:10 +08:00
IpmiLib.h MdeModulePkg: Add IpmiLib and Ppi/Protocol header file. 2015-12-23 08:16:20 +00:00
LockBoxLib.h
MemoryProfileLib.h MdeModulePkg: Introduce new library class MemoryProfileLib 2016-07-01 09:39:57 +08:00
NetLib.h MdeModulePkg: Refine type cast for pointer subtraction 2017-03-06 14:14:09 +08:00
NonDiscoverableDeviceRegistrationLib.h MdeModulePkg/NonDiscoverableDeviceRegistrationLib: Fix coding style issues 2016-12-20 10:51:25 +08:00
OemHookStatusCodeLib.h
PciHostBridgeLib.h MdeModulePkg/PciHostBridgeLib: Add ResourceAssigned field 2016-05-11 08:53:36 +08:00
PlatformBootManagerLib.h
PlatformHookLib.h
PlatformVarCleanupLib.h MdeModulePkg: Add PlatformVarCleanupLib library 2015-08-25 03:11:06 +00:00
RecoveryLib.h
ResetSystemLib.h MdeModulePkg: Add API ResetPlatformSpecific() to ResetSystemLib.h 2016-09-02 10:07:14 +08:00
S3Lib.h
SecurityManagementLib.h
SmmCorePlatformHookLib.h
SortLib.h
TcpIoLib.h
TpmMeasurementLib.h
UdpIoLib.h
UefiBootManagerLib.h MdeModulePkg/UefiBootManager: Add EfiBootManagerDispatchDeferredImages 2016-11-10 15:55:37 +08:00
UefiHiiServicesLib.h
VarCheckLib.h MdeModulePkg: Add VarCheckLib library 2015-08-25 02:58:09 +00:00