Mercurial > hg > Members > tobaru > cbc > CbC_llvm
diff lib/Support/StringMap.cpp @ 121:803732b1fca8
LLVM 5.0
author | kono |
---|---|
date | Fri, 27 Oct 2017 17:07:41 +0900 |
parents | 1172e4bd9c6f |
children |
line wrap: on
line diff
--- a/lib/Support/StringMap.cpp Fri Nov 25 19:14:25 2016 +0900 +++ b/lib/Support/StringMap.cpp Fri Oct 27 17:07:41 2017 +0900 @@ -52,14 +52,21 @@ void StringMapImpl::init(unsigned InitSize) { assert((InitSize & (InitSize-1)) == 0 && "Init Size must be a power of 2 or zero!"); - NumBuckets = InitSize ? InitSize : 16; + + unsigned NewNumBuckets = InitSize ? InitSize : 16; NumItems = 0; NumTombstones = 0; - TheTable = (StringMapEntryBase **)calloc(NumBuckets+1, + TheTable = (StringMapEntryBase **)calloc(NewNumBuckets+1, sizeof(StringMapEntryBase **) + sizeof(unsigned)); + if (TheTable == nullptr) + report_bad_alloc_error("Allocation of StringMap table failed."); + + // Set the member only if TheTable was successfully allocated + NumBuckets = NewNumBuckets; + // Allocate one extra bucket, set it to look filled so the iterators stop at // end. TheTable[NumBuckets] = (StringMapEntryBase*)2; @@ -215,6 +222,10 @@ StringMapEntryBase **NewTableArray = (StringMapEntryBase **)calloc(NewSize+1, sizeof(StringMapEntryBase *) + sizeof(unsigned)); + + if (NewTableArray == nullptr) + report_bad_alloc_error("Allocation of StringMap hash table failed."); + unsigned *NewHashArray = (unsigned *)(NewTableArray + NewSize + 1); NewTableArray[NewSize] = (StringMapEntryBase*)2;