mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-17 21:29:20 +00:00
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
This commit is contained in:
parent
48613b930a
commit
b54b315251
@ -184,14 +184,15 @@ void SmallPtrSetImpl::CopyFrom(const SmallPtrSetImpl &RHS) {
|
|||||||
if (isSmall() && RHS.isSmall())
|
if (isSmall() && RHS.isSmall())
|
||||||
assert(CurArraySize == RHS.CurArraySize &&
|
assert(CurArraySize == RHS.CurArraySize &&
|
||||||
"Cannot assign sets with different small sizes");
|
"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 we're becoming small, prepare to insert into our stack space
|
||||||
if (RHS.isSmall())
|
if (RHS.isSmall())
|
||||||
CurArray = &SmallArray[0];
|
CurArray = &SmallArray[0];
|
||||||
// Otherwise, allocate new heap space (unless we were the same size)
|
// Otherwise, allocate new heap space (unless we were the same size)
|
||||||
else if (CurArraySize != RHS.CurArraySize) {
|
else if (CurArraySize != RHS.CurArraySize) {
|
||||||
|
if (isSmall())
|
||||||
|
CurArray = (void**)malloc(sizeof(void*) * (RHS.CurArraySize+1));
|
||||||
|
else
|
||||||
CurArray = (void**)realloc(CurArray, sizeof(void*)*(RHS.CurArraySize+1));
|
CurArray = (void**)realloc(CurArray, sizeof(void*)*(RHS.CurArraySize+1));
|
||||||
assert(CurArray && "Failed to allocate memory?");
|
assert(CurArray && "Failed to allocate memory?");
|
||||||
}
|
}
|
||||||
@ -201,6 +202,9 @@ void SmallPtrSetImpl::CopyFrom(const SmallPtrSetImpl &RHS) {
|
|||||||
|
|
||||||
// Copy over the contents from the other set
|
// Copy over the contents from the other set
|
||||||
memcpy(CurArray, RHS.CurArray, sizeof(void*)*(CurArraySize+1));
|
memcpy(CurArray, RHS.CurArray, sizeof(void*)*(CurArraySize+1));
|
||||||
|
|
||||||
|
NumElements = RHS.NumElements;
|
||||||
|
NumTombstones = RHS.NumTombstones;
|
||||||
}
|
}
|
||||||
|
|
||||||
SmallPtrSetImpl::~SmallPtrSetImpl() {
|
SmallPtrSetImpl::~SmallPtrSetImpl() {
|
||||||
|
Loading…
Reference in New Issue
Block a user