(svn r22875) -Codechange: Add some asserts and checks to better prevent overflow of the argument to malloc. (monoid)
This commit is contained in:
@@ -204,6 +204,8 @@ public:
|
||||
FORCEINLINE void Include(T *new_item)
|
||||
{
|
||||
if (this->IsFull()) {
|
||||
assert(this->capacity < UINT_MAX / 2);
|
||||
|
||||
this->capacity *= 2;
|
||||
this->data = ReallocT<T*>(this->data, this->capacity + 1);
|
||||
}
|
||||
|
@@ -260,6 +260,7 @@ public:
|
||||
if (Capacity() >= new_size) return;
|
||||
/* calculate minimum block size we need to allocate
|
||||
* and ask allocation policy for some reasonable block size */
|
||||
assert(new_size < SIZE_MAX - header_size - tail_reserve);
|
||||
new_size = AllocPolicy(header_size + new_size + tail_reserve);
|
||||
|
||||
/* allocate new block and setup header */
|
||||
|
@@ -53,6 +53,9 @@ public:
|
||||
/** Default constructor. Preallocate space for items and header, then initialize header. */
|
||||
FixedSizeArray()
|
||||
{
|
||||
/* Ensure the size won't overflow. */
|
||||
assert_compile(C < (SIZE_MAX - HeaderSize) / Tsize);
|
||||
|
||||
/* allocate block for header + items (don't construct items) */
|
||||
data = (T*)((MallocT<byte>(HeaderSize + C * Tsize)) + HeaderSize);
|
||||
SizeRef() = 0; // initial number of items
|
||||
|
Reference in New Issue
Block a user