aboutsummaryrefslogtreecommitdiff
path: root/lib/Support/SmallPtrSet.cpp
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2007-07-18 19:54:15 +0000
committerOwen Anderson <resistor@mac.com>2007-07-18 19:54:15 +0000
commitb54b315251848ddab87ef9f2aa9aac92e3c68357 (patch)
tree735aab1cd8b6b44495a0719b2e6e4000453aa346 /lib/Support/SmallPtrSet.cpp
parent48613b930a34d6f98e7d3dd86aa49cc3dbd61c85 (diff)
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(). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40014 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/SmallPtrSet.cpp')
-rw-r--r--lib/Support/SmallPtrSet.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/Support/SmallPtrSet.cpp b/lib/Support/SmallPtrSet.cpp
index eb33c1541b..b2c5c42e27 100644
--- a/lib/Support/SmallPtrSet.cpp
+++ b/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() {