mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-25 03:30:37 +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 {
|
||||
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…
x
Reference in New Issue
Block a user