Skip to content

Commit

Permalink
Fix UBSan report in StringMap implementation.
Browse files Browse the repository at this point in the history
Use offsetof() instead of a member access within null pointer.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223402 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
vonosmas committed Dec 4, 2014
1 parent fb8dcb4 commit 8bc0067
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions include/llvm/ADT/StringMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,7 @@ class StringMapEntry : public StringMapEntryBase {
/// 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) {
Expand Down

0 comments on commit 8bc0067

Please sign in to comment.