[llvm-commits] [llvm] r40014 - /llvm/trunk/lib/Support/SmallPtrSet.cpp
Owen Anderson
resistor at mac.com
Wed Jul 18 12:54:16 PDT 2007
Author: resistor
Date: Wed Jul 18 14:54:15 2007
New Revision: 40014
URL: http://llvm.org/viewvc/llvm-project?rev=40014&view=rev
Log:
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().
Modified:
llvm/trunk/lib/Support/SmallPtrSet.cpp
Modified: llvm/trunk/lib/Support/SmallPtrSet.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/SmallPtrSet.cpp?rev=40014&r1=40013&r2=40014&view=diff
==============================================================================
--- llvm/trunk/lib/Support/SmallPtrSet.cpp (original)
+++ llvm/trunk/lib/Support/SmallPtrSet.cpp Wed Jul 18 14:54:15 2007
@@ -184,15 +184,16 @@
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 @@
// Copy over the contents from the other set
memcpy(CurArray, RHS.CurArray, sizeof(void*)*(CurArraySize+1));
+
+ NumElements = RHS.NumElements;
+ NumTombstones = RHS.NumTombstones;
}
SmallPtrSetImpl::~SmallPtrSetImpl() {
More information about the llvm-commits
mailing list