diff options
Diffstat (limited to 'llvm/lib/Support/SmallPtrSet.cpp')
-rw-r--r-- | llvm/lib/Support/SmallPtrSet.cpp | 20 |
1 files changed, 5 insertions, 15 deletions
diff --git a/llvm/lib/Support/SmallPtrSet.cpp b/llvm/lib/Support/SmallPtrSet.cpp index 119bb871d4c..fed4a17d663 100644 --- a/llvm/lib/Support/SmallPtrSet.cpp +++ b/llvm/lib/Support/SmallPtrSet.cpp @@ -32,9 +32,7 @@ void SmallPtrSetImplBase::shrink_and_clear() { NumNonEmpty = NumTombstones = 0; // Install the new array. Clear all the buckets to empty. - CurArray = (const void**)malloc(sizeof(void*) * CurArraySize); - if (CurArray == nullptr) - report_bad_alloc_error("Allocation of SmallPtrSet bucket array failed."); + CurArray = (const void**)safe_malloc(sizeof(void*) * CurArraySize); memset(CurArray, -1, CurArraySize*sizeof(void*)); } @@ -100,9 +98,7 @@ void SmallPtrSetImplBase::Grow(unsigned NewSize) { bool WasSmall = isSmall(); // Install the new array. Clear all the buckets to empty. - const void **NewBuckets = (const void**) malloc(sizeof(void*) * NewSize); - if (NewBuckets == nullptr) - report_bad_alloc_error("Allocation of SmallPtrSet bucket array failed."); + const void **NewBuckets = (const void**) safe_malloc(sizeof(void*) * NewSize); // Reset member only if memory was allocated successfully CurArray = NewBuckets; @@ -132,9 +128,7 @@ SmallPtrSetImplBase::SmallPtrSetImplBase(const void **SmallStorage, CurArray = SmallArray; // Otherwise, allocate new heap space (unless we were the same size) } else { - CurArray = (const void**)malloc(sizeof(void*) * that.CurArraySize); - if (CurArray == nullptr) - report_bad_alloc_error("Allocation of SmallPtrSet bucket array failed."); + CurArray = (const void**)safe_malloc(sizeof(void*) * that.CurArraySize); } // Copy over the that array. @@ -163,16 +157,12 @@ void SmallPtrSetImplBase::CopyFrom(const SmallPtrSetImplBase &RHS) { // Otherwise, allocate new heap space (unless we were the same size) } else if (CurArraySize != RHS.CurArraySize) { if (isSmall()) - CurArray = (const void**)malloc(sizeof(void*) * RHS.CurArraySize); + CurArray = (const void**)safe_malloc(sizeof(void*) * RHS.CurArraySize); else { - const void **T = (const void**)realloc(CurArray, + const void **T = (const void**)safe_realloc(CurArray, sizeof(void*) * RHS.CurArraySize); - if (!T) - free(CurArray); CurArray = T; } - if (CurArray == nullptr) - report_bad_alloc_error("Allocation of SmallPtrSet bucket array failed."); } CopyHelper(RHS); |