summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Demangle/ItaniumDemangle.cpp
diff options
context:
space:
mode:
authorErik Pilkington <erik.pilkington@gmail.com>2018-07-23 22:23:04 +0000
committerErik Pilkington <erik.pilkington@gmail.com>2018-07-23 22:23:04 +0000
commit28e08a0a617c128259015614e8f90c98d2487ba6 (patch)
tree2ddee91cf7a77f1c79125ee99f9aaf5f0c78b1a7 /llvm/lib/Demangle/ItaniumDemangle.cpp
parent247aac81abee8d7b4b9635347d0ab9a287e5b441 (diff)
downloadbcm5719-llvm-28e08a0a617c128259015614e8f90c98d2487ba6.tar.gz
bcm5719-llvm-28e08a0a617c128259015614e8f90c98d2487ba6.zip
[demangler] call terminate() if allocation failed
We really should set *status to memory_alloc_failure, but we need to refactor the demangler a bit to properly propagate the failure up the stack. Until then, its better to explicitly terminate then rely on a null dereference crash. rdar://31240372 llvm-svn: 337759
Diffstat (limited to 'llvm/lib/Demangle/ItaniumDemangle.cpp')
-rw-r--r--llvm/lib/Demangle/ItaniumDemangle.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/llvm/lib/Demangle/ItaniumDemangle.cpp b/llvm/lib/Demangle/ItaniumDemangle.cpp
index 10ec84815e9..30ad30d8271 100644
--- a/llvm/lib/Demangle/ItaniumDemangle.cpp
+++ b/llvm/lib/Demangle/ItaniumDemangle.cpp
@@ -1761,13 +1761,17 @@ class BumpPointerAllocator {
BlockMeta* BlockList = nullptr;
void grow() {
- char* NewMeta = new char[AllocSize];
+ char* NewMeta = static_cast<char *>(std::malloc(AllocSize));
+ if (NewMeta == nullptr)
+ std::terminate();
BlockList = new (NewMeta) BlockMeta{BlockList, 0};
}
void* allocateMassive(size_t NBytes) {
NBytes += sizeof(BlockMeta);
- BlockMeta* NewMeta = reinterpret_cast<BlockMeta*>(new char[NBytes]);
+ BlockMeta* NewMeta = reinterpret_cast<BlockMeta*>(std::malloc(NBytes));
+ if (NewMeta == nullptr)
+ std::terminate();
BlockList->Next = new (NewMeta) BlockMeta{BlockList->Next, 0};
return static_cast<void*>(NewMeta + 1);
}
@@ -1793,7 +1797,7 @@ public:
BlockMeta* Tmp = BlockList;
BlockList = BlockList->Next;
if (reinterpret_cast<char*>(Tmp) != InitialBuffer)
- delete[] reinterpret_cast<char*>(Tmp);
+ std::free(Tmp);
}
BlockList = new (InitialBuffer) BlockMeta{nullptr, 0};
}
@@ -1823,10 +1827,15 @@ class PODSmallVector {
size_t S = size();
if (isInline()) {
auto* Tmp = static_cast<T*>(std::malloc(NewCap * sizeof(T)));
+ if (Tmp == nullptr)
+ std::terminate();
std::copy(First, Last, Tmp);
First = Tmp;
- } else
+ } else {
First = static_cast<T*>(std::realloc(First, NewCap * sizeof(T)));
+ if (First == nullptr)
+ std::terminate();
+ }
Last = First + S;
Cap = First + NewCap;
}
OpenPOWER on IntegriCloud