audk/SecurityPkg/Library
Hao Wu 4333b99d28 SecurityPkg: 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: Chao Zhang <chao.b.zhang@intel.com>
2017-03-06 14:15:36 +08:00
..
AuthVariableLib SecurityPkg: enhance secure boot Config Dxe & Time Based AuthVariable. 2017-02-20 10:09:53 +08:00
DxeDeferImageLoadLib SecurityPkg: Fix typos in comments 2016-11-15 15:45:31 +08:00
DxeImageAuthenticationStatusLib SecurityPkg: Convert all .uni files to utf-8 2015-12-15 04:58:32 +00:00
DxeImageVerificationLib SecurityPkg: Refine type cast for pointer subtraction 2017-03-06 14:15:36 +08:00
DxeRsa2048Sha256GuidedSectionExtractLib SecurityPkg: Fix typos in comments 2016-11-15 15:45:31 +08:00
DxeTcg2PhysicalPresenceLib SecurityPkg: Tcg2PhysicalPresence: Define TCG2 PP Flags Initial Pcd 2016-12-29 09:45:15 +08:00
DxeTcgPhysicalPresenceLib Revert old "Enable BlockSid related PP actions" patch series. 2016-11-23 16:30:03 +08:00
DxeTpm2MeasureBootLib SecurityPkg: Use IsZeroGuid API for zero GUID checking 2016-08-31 11:15:13 +08:00
DxeTpmMeasureBootLib SecurityPkg: Refine type cast for pointer subtraction 2017-03-06 14:15:36 +08:00
DxeTpmMeasurementLib SecurityPkg: Convert all .uni files to utf-8 2015-12-15 04:58:32 +00:00
DxeTrEEPhysicalPresenceLib SecurityPkg: Update protocol usage in module INF files. 2016-04-13 14:52:58 +08:00
FmpAuthenticationLibPkcs7 SecurityPkg/FmpAuthenticationLib: Refine to compare with same type 2017-01-12 21:26:29 +08:00
FmpAuthenticationLibRsa2048Sha256 SecurityPkg/FmpAuthenticationLib: Refine to compare with same type 2017-01-12 21:26:29 +08:00
HashInstanceLibSha1 SecurityPkg: Fix typo 'Ihis' with 'This' in codes 2016-10-18 09:41:56 +08:00
HashInstanceLibSha256 SecurityPkg: Fix typo 'Ihis' with 'This' in codes 2016-10-18 09:41:56 +08:00
HashLibBaseCryptoRouter SecurityPkg HashLibRouter: Avoid incorrect PcdTcg2HashAlgorithmBitmap 2017-02-08 18:52:07 +08:00
HashLibTpm2 SecurityPkg: Fix typo 'Ihis' with 'This' in codes 2016-10-18 09:41:56 +08:00
OpalPasswordSupportLib SecurityPkg-Opal(1): Use fixed SMM communication buffer in OPAL password lib. 2016-04-29 12:49:23 +08:00
PeiRsa2048Sha256GuidedSectionExtractLib SecurityPkg: Fix typos in comments 2016-11-15 15:45:31 +08:00
PeiTcg2PhysicalPresenceLib SecurityPkg Tcg2PPLib: Support BlockSID related actions 2016-11-28 14:50:42 +08:00
PlatformSecureLibNull SecurityPkg: Update PlatformSecureLibNull with PCD to get physical presence. 2016-06-29 09:43:00 +08:00
SmmTcg2PhysicalPresenceLib SecurityPkg Tcg2PPLib: Support BlockSID related actions 2016-11-28 14:50:42 +08:00
Tcg2PpVendorLibNull SecurityPkg: Convert all .uni files to utf-8 2015-12-15 04:58:32 +00:00
TcgPpVendorLibNull SecurityPkg: Convert all .uni files to utf-8 2015-12-15 04:58:32 +00:00
TcgStorageCoreLib SecurityPkg TcgStorageCoreLib: ASSERT to ensure 'ByteSeq' is not NULL 2016-11-22 16:31:44 +08:00
TcgStorageOpalLib SecurityPkg: Fix typos in comments 2016-11-15 15:45:31 +08:00
Tpm2CommandLib SecurityPkg: Refine type cast for pointer subtraction 2017-03-06 14:15:36 +08:00
Tpm2DeviceLibDTpm SecurityPkg: Fix typo 'Ihis' with 'This' in codes 2016-10-18 09:41:56 +08:00
Tpm2DeviceLibRouter SecurityPkg: Fix typo 'Ihis' with 'This' in codes 2016-10-18 09:41:56 +08:00
Tpm2DeviceLibTcg2 SecurityPkg: Fix typo 'Ihis' with 'This' in codes 2016-10-18 09:41:56 +08:00
Tpm2DeviceLibTrEE SecurityPkg: Fix typo 'Ihis' with 'This' in codes 2016-10-18 09:41:56 +08:00
Tpm12CommandLib SecurityPkg/Tpm12CommandLib: Always check response returnCode 2017-01-25 14:18:30 -08:00
Tpm12DeviceLibDTpm SecurityPkg : Tpm12DeviceLibDTpm: Fix TPM12 wrong Response Tag check 2016-06-08 15:14:56 +08:00
Tpm12DeviceLibTcg SecurityPkg: Fix typo 'Ihis' with 'This' in codes 2016-10-18 09:41:56 +08:00
TpmCommLib SecurityPkg: Convert all .uni files to utf-8 2015-12-15 04:58:32 +00:00
TrEEPpVendorLibNull SecurityPkg: Convert all .uni files to utf-8 2015-12-15 04:58:32 +00:00