Reviewed-by: Star Zeng <star.z...@intel.com>

Thanks,
Star
-----Original Message-----
From: Wu, Hao A 
Sent: Tuesday, February 13, 2018 10:28 AM
To: edk2-devel@lists.01.org
Cc: Wu, Hao A <hao.a...@intel.com>; Kinney, Michael D 
<michael.d.kin...@intel.com>; Sean Brogan <sean.bro...@microsoft.com>; Yao, 
Jiewen <jiewen....@intel.com>; Zeng, Star <star.z...@intel.com>; Dong, Eric 
<eric.d...@intel.com>; Ni, Ruiyu <ruiyu...@intel.com>
Subject: [PATCH] MdeModulePkg/BmpSupportLib: Refine type cast for pointer 
subtraction

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.kin...@intel.com>
Cc: Sean Brogan <sean.bro...@microsoft.com>
Cc: Jiewen Yao <jiewen....@intel.com>
Cc: Star Zeng <star.z...@intel.com>
Cc: Eric Dong <eric.d...@intel.com>
Cc: Ruiyu Ni <ruiyu...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Hao Wu <hao.a...@intel.com>
---
 MdeModulePkg/Library/BaseBmpSupportLib/BmpSupportLib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/MdeModulePkg/Library/BaseBmpSupportLib/BmpSupportLib.c 
b/MdeModulePkg/Library/BaseBmpSupportLib/BmpSupportLib.c
index 2c95e91ecc..467cd6a58d 100644
--- a/MdeModulePkg/Library/BaseBmpSupportLib/BmpSupportLib.c
+++ b/MdeModulePkg/Library/BaseBmpSupportLib/BmpSupportLib.c
@@ -426,7 +426,7 @@ TranslateBmpToGopBlt (
 
     }
 
-    ImageIndex = (UINTN)(Image - ImageHeader);
+    ImageIndex = (UINTN)Image - (UINTN)ImageHeader;
     if ((ImageIndex % 4) != 0) {
       //
       // Bmp Image starts each row on a 32-bit boundary!
--
2.12.0.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to