audk/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe
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
..
SecureBootConfig.vfr SecurityPkg: Fix potential bug in Security Boot dxe. 2017-03-01 15:40:50 +08:00
SecureBootConfigDevicePath.c Update all the code to consume the ConvertDevicePathToText, ConvertDevicePathNodeToText, ConvertTextToDevicePath and ConvertTextToDeviceNode APIs in DevicePathLib. 2013-07-26 03:14:08 +00:00
SecureBootConfigDriver.c Enable/Disable Secured Boot by 'Secure Boot Configuration' Page which is under Setup browser. 2011-10-28 03:46:20 +00:00
SecureBootConfigDxe.inf SecurityPkg SecureBootConfigDxe: Add check for the external PE/COFF image. 2016-07-14 15:04:53 +08:00
SecureBootConfigDxe.uni SecurityPkg: Convert all .uni files to utf-8 2015-12-15 04:58:32 +00:00
SecureBootConfigDxeExtra.uni SecurityPkg: Convert all .uni files to utf-8 2015-12-15 04:58:32 +00:00
SecureBootConfigFileExplorer.c SecurityPkg/SecureBootConfigDxe: Declare EFIAPI for the ChooseFile handlers 2016-03-24 09:26:46 +01:00
SecureBootConfigImpl.c SecurityPkg: Refine type cast for pointer subtraction 2017-03-06 14:15:36 +08:00
SecureBootConfigImpl.h SecurityPkg: Fix potential bug in Security Boot dxe. 2017-03-01 15:40:50 +08:00
SecureBootConfigMisc.c SecurityPkg/SecureBootConfigDxe: Use StrToGuid in BaseLib 2017-02-28 11:30:34 +08:00
SecureBootConfigNvData.h SecurityPkg: SecureBootConfigDxe: Remove SecureBoot UI change for Customized Secure Boot 2016-05-04 09:13:51 +08:00
SecureBootConfigStrings.uni SecurityPkg: SecureBootConfigDxe: Remove SecureBoot UI change for Customized Secure Boot 2016-05-04 09:13:51 +08:00