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>
This commit is contained in:
Marvin.Haeuser@outlook.com 2018-11-01 04:08:35 +08:00 committed by Liming Gao
parent 88e8498f8a
commit 498cb29dfd
1 changed files with 1 additions and 1 deletions

View File

@ -869,7 +869,7 @@ typedef UINTN *BASE_LIST;
@return A pointer to the structure from one of it's elements. @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. Rounds a value up to the next boundary using a specified alignment.