]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdePkg/Base.h: Implement BASE_CR() via OFFSET_OF().
authorMarvin.Haeuser@outlook.com <Marvin.Haeuser@outlook.com>
Wed, 31 Oct 2018 20:08:35 +0000 (04:08 +0800)
committerLiming Gao <liming.gao@intel.com>
Fri, 2 Nov 2018 14:15:54 +0000 (22:15 +0800)
Replace the current NULL pointer dereference to retrieve Field's
offset with a call to OFFSET_OF().  This is implemented via
__builtin_offsetof for GCC and Clang, which eliminates UB caught by
Clang UndefinedBehaviorSanitizer.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marvin Haeuser <Marvin.Haeuser@outlook.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
MdePkg/Include/Base.h

index 523192fd79fc945c1ac122ae06da72aab3067972..bc877d8125a5a63de187ca7e5b772be00ed055d9 100644 (file)
@@ -869,7 +869,7 @@ typedef UINTN  *BASE_LIST;
   @return  A pointer to the structure from one of it's elements.\r
 \r
 **/\r
-#define BASE_CR(Record, TYPE, Field)  ((TYPE *) ((CHAR8 *) (Record) - (CHAR8 *) &(((TYPE *) 0)->Field)))\r
+#define BASE_CR(Record, TYPE, Field)  ((TYPE *) ((CHAR8 *) (Record) - OFFSET_OF (TYPE, Field)))\r
 \r
 /**\r
   Rounds a value up to the next boundary using a specified alignment.\r