[llvm] r223402 - Fix UBSan report in StringMap implementation.
Alexey Samsonov
vonosmas at gmail.com
Thu Dec 4 14:45:31 PST 2014
Author: samsonov
Date: Thu Dec 4 16:45:31 2014
New Revision: 223402
URL: http://llvm.org/viewvc/llvm-project?rev=223402&view=rev
Log:
Fix UBSan report in StringMap implementation.
Use offsetof() instead of a member access within null pointer.
Modified:
llvm/trunk/include/llvm/ADT/StringMap.h
Modified: llvm/trunk/include/llvm/ADT/StringMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/StringMap.h?rev=223402&r1=223401&r2=223402&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/StringMap.h (original)
+++ llvm/trunk/include/llvm/ADT/StringMap.h Thu Dec 4 16:45:31 2014
@@ -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) {
More information about the llvm-commits
mailing list