diff options
author | Michael J. Spencer <bigcheesegs@gmail.com> | 2010-12-03 05:42:25 +0000 |
---|---|---|
committer | Michael J. Spencer <bigcheesegs@gmail.com> | 2010-12-03 05:42:25 +0000 |
commit | 0dda5437f8044269a90acddad822866056a0c8b3 (patch) | |
tree | f1da79570f8532ba9dad8488575c04fa59b67da0 /lib/Support/Twine.cpp | |
parent | b83769f36afe5221ca6aa7741561801836a179cb (diff) |
Support/ADT/Twine: Make toNullTerminatedStringRef not rely on UB :(.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120791 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/Twine.cpp')
-rw-r--r-- | lib/Support/Twine.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/Support/Twine.cpp b/lib/Support/Twine.cpp index 4f6f479a7e..75cea2961a 100644 --- a/lib/Support/Twine.cpp +++ b/lib/Support/Twine.cpp @@ -31,10 +31,18 @@ StringRef Twine::toStringRef(SmallVectorImpl<char> &Out) const { } StringRef Twine::toNullTerminatedStringRef(SmallVectorImpl<char> &Out) const { - if (isSingleStringRef()) { - StringRef sr = getSingleStringRef(); - if (*(sr.begin() + sr.size()) == 0) - return sr; + if (isUnary()) { + switch (getLHSKind()) { + case CStringKind: + // Already null terminated, yay! + return StringRef(static_cast<const char*>(LHS)); + case StdStringKind: { + const std::string *str = static_cast<const std::string*>(LHS); + return StringRef(str->c_str(), str->size()); + } + default: + break; + } } toVector(Out); Out.push_back(0); |