mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-25 19:29:53 +00:00
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
This commit is contained in:
parent
b83769f36a
commit
0dda5437f8
@ -31,10 +31,18 @@ StringRef Twine::toStringRef(SmallVectorImpl<char> &Out) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
StringRef Twine::toNullTerminatedStringRef(SmallVectorImpl<char> &Out) const {
|
StringRef Twine::toNullTerminatedStringRef(SmallVectorImpl<char> &Out) const {
|
||||||
if (isSingleStringRef()) {
|
if (isUnary()) {
|
||||||
StringRef sr = getSingleStringRef();
|
switch (getLHSKind()) {
|
||||||
if (*(sr.begin() + sr.size()) == 0)
|
case CStringKind:
|
||||||
return sr;
|
// 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);
|
toVector(Out);
|
||||||
Out.push_back(0);
|
Out.push_back(0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user