[llvm-commits] [llvm] r120791 - /llvm/trunk/lib/Support/Twine.cpp
Michael J. Spencer
bigcheesegs at gmail.com
Thu Dec 2 21:42:26 PST 2010
Author: mspencer
Date: Thu Dec 2 23:42:25 2010
New Revision: 120791
URL: http://llvm.org/viewvc/llvm-project?rev=120791&view=rev
Log:
Support/ADT/Twine: Make toNullTerminatedStringRef not rely on UB :(.
Modified:
llvm/trunk/lib/Support/Twine.cpp
Modified: llvm/trunk/lib/Support/Twine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Twine.cpp?rev=120791&r1=120790&r2=120791&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Twine.cpp (original)
+++ llvm/trunk/lib/Support/Twine.cpp Thu Dec 2 23:42:25 2010
@@ -31,10 +31,18 @@
}
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);
More information about the llvm-commits
mailing list