Fix UBSan report in StringMap implementation.

Use offsetof() instead of a member access within null pointer.

llvm-svn: 223402
This commit is contained in:
Alexey Samsonov 2014-12-04 22:45:31 +00:00
parent a3ae0b3b5b
commit 36b525feb0
1 changed files with 1 additions and 4 deletions

View File

@ -182,10 +182,7 @@ public:
/// GetStringMapEntryFromValue - Given a value that is known to be embedded
/// into a StringMapEntry, return the StringMapEntry itself.
static StringMapEntry &GetStringMapEntryFromValue(ValueTy &V) {
StringMapEntry *EPtr = 0;
char *Ptr = reinterpret_cast<char*>(&V) -
(reinterpret_cast<char*>(&EPtr->second) -
reinterpret_cast<char*>(EPtr));
char *Ptr = reinterpret_cast<char *>(&V) - offsetof(StringMapEntry, second);
return *reinterpret_cast<StringMapEntry*>(Ptr);
}
static const StringMapEntry &GetStringMapEntryFromValue(const ValueTy &V) {