mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 19:23:23 +01:00
Support/ADT/Twine: Make toNullTerminatedStringRef not rely on UB :(.
llvm-svn: 120791
This commit is contained in:
parent
96236c93ff
commit
5328e94513
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user