diff options
author | Patrick Wildt <patrick@cvs.openbsd.org> | 2018-04-06 14:26:57 +0000 |
---|---|---|
committer | Patrick Wildt <patrick@cvs.openbsd.org> | 2018-04-06 14:26:57 +0000 |
commit | 5b0514634148624e8c36b28a654e89ce77f7cc92 (patch) | |
tree | c8c69996dfcbfd77243169cfb2652e27604a50d3 /gnu/llvm/lib/Support/SmallPtrSet.cpp | |
parent | 2d2537b3985221b371b2a4a1471fa2e56b846bf0 (diff) |
Import LLVM 6.0.1 release including clang, lld and lldb.
"where is the kaboom?" deraadt@
Diffstat (limited to 'gnu/llvm/lib/Support/SmallPtrSet.cpp')
-rw-r--r-- | gnu/llvm/lib/Support/SmallPtrSet.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/gnu/llvm/lib/Support/SmallPtrSet.cpp b/gnu/llvm/lib/Support/SmallPtrSet.cpp index aa12e85fa4c..119bb871d4c 100644 --- a/gnu/llvm/lib/Support/SmallPtrSet.cpp +++ b/gnu/llvm/lib/Support/SmallPtrSet.cpp @@ -15,6 +15,7 @@ #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/DenseMapInfo.h" #include "llvm/Support/MathExtras.h" +#include "llvm/Support/ErrorHandling.h" #include <algorithm> #include <cassert> #include <cstdlib> @@ -32,7 +33,9 @@ void SmallPtrSetImplBase::shrink_and_clear() { // Install the new array. Clear all the buckets to empty. CurArray = (const void**)malloc(sizeof(void*) * CurArraySize); - assert(CurArray && "Failed to allocate memory?"); + if (CurArray == nullptr) + report_bad_alloc_error("Allocation of SmallPtrSet bucket array failed."); + memset(CurArray, -1, CurArraySize*sizeof(void*)); } @@ -58,6 +61,7 @@ SmallPtrSetImplBase::insert_imp_big(const void *Ptr) { else ++NumNonEmpty; // Track density. *Bucket = Ptr; + incrementEpoch(); return std::make_pair(Bucket, true); } @@ -96,8 +100,12 @@ void SmallPtrSetImplBase::Grow(unsigned NewSize) { bool WasSmall = isSmall(); // Install the new array. Clear all the buckets to empty. - CurArray = (const void**)malloc(sizeof(void*) * NewSize); - assert(CurArray && "Failed to allocate memory?"); + const void **NewBuckets = (const void**) malloc(sizeof(void*) * NewSize); + if (NewBuckets == nullptr) + report_bad_alloc_error("Allocation of SmallPtrSet bucket array failed."); + + // Reset member only if memory was allocated successfully + CurArray = NewBuckets; CurArraySize = NewSize; memset(CurArray, -1, NewSize*sizeof(void*)); @@ -125,7 +133,8 @@ SmallPtrSetImplBase::SmallPtrSetImplBase(const void **SmallStorage, // Otherwise, allocate new heap space (unless we were the same size) } else { CurArray = (const void**)malloc(sizeof(void*) * that.CurArraySize); - assert(CurArray && "Failed to allocate memory?"); + if (CurArray == nullptr) + report_bad_alloc_error("Allocation of SmallPtrSet bucket array failed."); } // Copy over the that array. @@ -162,7 +171,8 @@ void SmallPtrSetImplBase::CopyFrom(const SmallPtrSetImplBase &RHS) { free(CurArray); CurArray = T; } - assert(CurArray && "Failed to allocate memory?"); + if (CurArray == nullptr) + report_bad_alloc_error("Allocation of SmallPtrSet bucket array failed."); } CopyHelper(RHS); |