aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Demangle/MicrosoftDemangle.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Demangle/MicrosoftDemangle.cpp')
-rw-r--r--llvm/lib/Demangle/MicrosoftDemangle.cpp22
1 files changed, 5 insertions, 17 deletions
diff --git a/llvm/lib/Demangle/MicrosoftDemangle.cpp b/llvm/lib/Demangle/MicrosoftDemangle.cpp
index b4e98a2..c21b0a3 100644
--- a/llvm/lib/Demangle/MicrosoftDemangle.cpp
+++ b/llvm/lib/Demangle/MicrosoftDemangle.cpp
@@ -246,7 +246,10 @@ demanglePointerCVQualifiers(StringView &MangledName) {
StringView Demangler::copyString(StringView Borrowed) {
char *Stable = Arena.allocUnalignedBuffer(Borrowed.size());
- std::memcpy(Stable, Borrowed.begin(), Borrowed.size());
+ // This is not a micro-optimization, it avoids UB, should Borrowed be an null
+ // buffer.
+ if (Borrowed.size())
+ std::memcpy(Stable, Borrowed.begin(), Borrowed.size());
return {Stable, Borrowed.size()};
}
@@ -970,9 +973,6 @@ void Demangler::memorizeIdentifier(IdentifierNode *Identifier) {
// Render this class template name into a string buffer so that we can
// memorize it for the purpose of back-referencing.
OutputBuffer OB;
- if (!initializeOutputBuffer(nullptr, nullptr, OB, 1024))
- // FIXME: Propagate out-of-memory as an error?
- std::terminate();
Identifier->output(OB, OF_Default);
StringView Owned = copyString(OB);
memorizeString(Owned);
@@ -1283,11 +1283,6 @@ Demangler::demangleStringLiteral(StringView &MangledName) {
EncodedStringLiteralNode *Result = Arena.alloc<EncodedStringLiteralNode>();
- // Must happen before the first `goto StringLiteralError`.
- if (!initializeOutputBuffer(nullptr, nullptr, OB, 1024))
- // FIXME: Propagate out-of-memory as an error?
- std::terminate();
-
// Prefix indicating the beginning of a string literal
if (!MangledName.consumeFront("@_"))
goto StringLiteralError;
@@ -1446,9 +1441,6 @@ Demangler::demangleLocallyScopedNamePiece(StringView &MangledName) {
// Render the parent symbol's name into a buffer.
OutputBuffer OB;
- if (!initializeOutputBuffer(nullptr, nullptr, OB, 1024))
- // FIXME: Propagate out-of-memory as an error?
- std::terminate();
OB << '`';
Scope->output(OB, OF_Default);
OB << '\'';
@@ -2311,8 +2303,6 @@ void Demangler::dumpBackReferences() {
// Create an output stream so we can render each type.
OutputBuffer OB;
- if (!initializeOutputBuffer(nullptr, nullptr, OB, 1024))
- std::terminate();
for (size_t I = 0; I < Backrefs.FunctionParamCount; ++I) {
OB.setCurrentPosition(0);
@@ -2339,7 +2329,6 @@ char *llvm::microsoftDemangle(const char *MangledName, size_t *NMangled,
char *Buf, size_t *N,
int *Status, MSDemangleFlags Flags) {
Demangler D;
- OutputBuffer OB;
StringView Name{MangledName};
SymbolNode *AST = D.parse(Name);
@@ -2364,9 +2353,8 @@ char *llvm::microsoftDemangle(const char *MangledName, size_t *NMangled,
int InternalStatus = demangle_success;
if (D.Error)
InternalStatus = demangle_invalid_mangled_name;
- else if (!initializeOutputBuffer(Buf, N, OB, 1024))
- InternalStatus = demangle_memory_alloc_failure;
else {
+ OutputBuffer OB(Buf, N);
AST->output(OB, OF);
OB += '\0';
if (N != nullptr)