summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Twine.cpp
diff options
context:
space:
mode:
authorMichael J. Spencer <bigcheesegs@gmail.com>2010-12-03 05:42:25 +0000
committerMichael J. Spencer <bigcheesegs@gmail.com>2010-12-03 05:42:25 +0000
commit73e60d029c0ff0406d4e185f48183c30b83daa49 (patch)
treeddba5d81fb3db259f6344029cc9752da8f03933a /llvm/lib/Support/Twine.cpp
parent31e310cda0e1660e3bada29096e29796aabe059a (diff)
downloadbcm5719-llvm-73e60d029c0ff0406d4e185f48183c30b83daa49.tar.gz
bcm5719-llvm-73e60d029c0ff0406d4e185f48183c30b83daa49.zip
Support/ADT/Twine: Make toNullTerminatedStringRef not rely on UB :(.
llvm-svn: 120791
Diffstat (limited to 'llvm/lib/Support/Twine.cpp')
-rw-r--r--llvm/lib/Support/Twine.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/llvm/lib/Support/Twine.cpp b/llvm/lib/Support/Twine.cpp
index 4f6f479a7ea..75cea2961a9 100644
--- a/llvm/lib/Support/Twine.cpp
+++ b/llvm/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);
OpenPOWER on IntegriCloud