]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/BmpSupportLib: Refine type cast for pointer subtraction
authorHao Wu <hao.a.wu@intel.com>
Tue, 13 Feb 2018 02:23:51 +0000 (10:23 +0800)
committerHao Wu <hao.a.wu@intel.com>
Wed, 14 Feb 2018 00:19:47 +0000 (08:19 +0800)
Since the pointer subtraction here is not performed by pointers to
elements of the same array object. This might lead to potential issues,
such behavior is undefined according to C11 standard.

Refine the pointer subtraction expressions by casting each pointer to
UINTN first and then perform the subtraction.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
MdeModulePkg/Library/BaseBmpSupportLib/BmpSupportLib.c

index 2c95e91ecc6d734d5d00850226e2d45db7dd6d60..467cd6a58db312b51b85c969b7681a82765df0f9 100644 (file)
@@ -426,7 +426,7 @@ TranslateBmpToGopBlt (
 \r
     }\r
 \r
-    ImageIndex = (UINTN)(Image - ImageHeader);\r
+    ImageIndex = (UINTN)Image - (UINTN)ImageHeader;\r
     if ((ImageIndex % 4) != 0) {\r
       //\r
       // Bmp Image starts each row on a 32-bit boundary!\r