diff options
author | Marvin.Haeuser@outlook.com <Marvin.Haeuser@outlook.com> | 2018-11-01 04:08:35 +0800 |
---|---|---|
committer | Liming Gao <liming.gao@intel.com> | 2018-11-02 22:15:54 +0800 |
commit | 498cb29dfdcc7232f7b0693e266555c19c43ae20 (patch) | |
tree | 6a4ad28f86252c97a2b02633acf4873e3822d2c8 /MdePkg/Include/Base.h | |
parent | 88e8498f8a72cff1f7af6852ec8166772913399e (diff) | |
download | edk2-498cb29dfdcc7232f7b0693e266555c19c43ae20.tar.gz edk2-498cb29dfdcc7232f7b0693e266555c19c43ae20.tar.bz2 edk2-498cb29dfdcc7232f7b0693e266555c19c43ae20.zip |
MdePkg/Base.h: Implement BASE_CR() via OFFSET_OF().
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>
Diffstat (limited to 'MdePkg/Include/Base.h')
-rw-r--r-- | MdePkg/Include/Base.h | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h index 523192fd79..bc877d8125 100644 --- a/MdePkg/Include/Base.h +++ b/MdePkg/Include/Base.h @@ -869,7 +869,7 @@ typedef UINTN *BASE_LIST; @return A pointer to the structure from one of it's elements.
**/
-#define BASE_CR(Record, TYPE, Field) ((TYPE *) ((CHAR8 *) (Record) - (CHAR8 *) &(((TYPE *) 0)->Field)))
+#define BASE_CR(Record, TYPE, Field) ((TYPE *) ((CHAR8 *) (Record) - OFFSET_OF (TYPE, Field)))
/**
Rounds a value up to the next boundary using a specified alignment.
|