diff options
author | Owen Anderson <resistor@mac.com> | 2007-07-18 19:54:15 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2007-07-18 19:54:15 +0000 |
commit | e21f27085881ac20297d646654ead6389982d4da (patch) | |
tree | 35d6ec4db2b5742bd91b68e16f494a998c66465f /llvm/lib/Support/SmallPtrSet.cpp | |
parent | 0f0019c36e5252e4356b16f3cc4c7474a3435d47 (diff) | |
download | bcm5719-llvm-e21f27085881ac20297d646654ead6389982d4da.tar.gz bcm5719-llvm-e21f27085881ac20297d646654ead6389982d4da.zip |
Fix an issue where assignments that caused a SmallPtrSet to become non-small
would result in calling realloc() on a null pointer. Instead, if we encounter
this situation, make a normal call to malloc().
llvm-svn: 40014
Diffstat (limited to 'llvm/lib/Support/SmallPtrSet.cpp')
-rw-r--r-- | llvm/lib/Support/SmallPtrSet.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/llvm/lib/Support/SmallPtrSet.cpp b/llvm/lib/Support/SmallPtrSet.cpp index eb33c1541b0..b2c5c42e279 100644 --- a/llvm/lib/Support/SmallPtrSet.cpp +++ b/llvm/lib/Support/SmallPtrSet.cpp @@ -184,15 +184,16 @@ void SmallPtrSetImpl::CopyFrom(const SmallPtrSetImpl &RHS) { if (isSmall() && RHS.isSmall()) assert(CurArraySize == RHS.CurArraySize && "Cannot assign sets with different small sizes"); - NumElements = RHS.NumElements; - NumTombstones = RHS.NumTombstones; - + // If we're becoming small, prepare to insert into our stack space if (RHS.isSmall()) CurArray = &SmallArray[0]; // Otherwise, allocate new heap space (unless we were the same size) else if (CurArraySize != RHS.CurArraySize) { - CurArray = (void**)realloc(CurArray, sizeof(void*)*(RHS.CurArraySize+1)); + if (isSmall()) + CurArray = (void**)malloc(sizeof(void*) * (RHS.CurArraySize+1)); + else + CurArray = (void**)realloc(CurArray, sizeof(void*)*(RHS.CurArraySize+1)); assert(CurArray && "Failed to allocate memory?"); } @@ -201,6 +202,9 @@ void SmallPtrSetImpl::CopyFrom(const SmallPtrSetImpl &RHS) { // Copy over the contents from the other set memcpy(CurArray, RHS.CurArray, sizeof(void*)*(CurArraySize+1)); + + NumElements = RHS.NumElements; + NumTombstones = RHS.NumTombstones; } SmallPtrSetImpl::~SmallPtrSetImpl() { |