[libcxxabi] r337759 - [demangler] call terminate() if allocation failed
Erik Pilkington via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 23 15:23:04 PDT 2018
Author: epilk
Date: Mon Jul 23 15:23:04 2018
New Revision: 337759
URL: http://llvm.org/viewvc/llvm-project?rev=337759&view=rev
Log:
[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
Modified:
libcxxabi/trunk/src/cxa_demangle.cpp
libcxxabi/trunk/src/demangle/Utility.h
Modified: libcxxabi/trunk/src/cxa_demangle.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_demangle.cpp?rev=337759&r1=337758&r2=337759&view=diff
==============================================================================
--- libcxxabi/trunk/src/cxa_demangle.cpp (original)
+++ libcxxabi/trunk/src/cxa_demangle.cpp Mon Jul 23 15:23:04 2018
@@ -1771,13 +1771,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);
}
@@ -1803,7 +1807,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};
}
@@ -1833,10 +1837,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;
}
Modified: libcxxabi/trunk/src/demangle/Utility.h
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/demangle/Utility.h?rev=337759&r1=337758&r2=337759&view=diff
==============================================================================
--- libcxxabi/trunk/src/demangle/Utility.h (original)
+++ libcxxabi/trunk/src/demangle/Utility.h Mon Jul 23 15:23:04 2018
@@ -35,6 +35,8 @@ class OutputStream {
if (BufferCapacity < N + CurrentPosition)
BufferCapacity = N + CurrentPosition;
Buffer = static_cast<char *>(std::realloc(Buffer, BufferCapacity));
+ if (Buffer == nullptr)
+ std::terminate();
}
}
@@ -76,6 +78,8 @@ public:
if (!StartBuf || !Size) {
StartBuf = static_cast<char *>(std::malloc(AllocSize));
+ if (StartBuf == nullptr)
+ std::terminate();
Size = &AllocSize;
}
More information about the cfe-commits
mailing list