From 0464e9f864da7b71fdf7b568916596fbb8a614bb Mon Sep 17 00:00:00 2001 From: rubidium Date: Fri, 9 Jan 2009 15:01:15 +0000 Subject: [PATCH] (svn r14935) -Fix [FS#2498]: the new operator may not return NULL, so don't. --- src/oldpool.h | 10 +++++++--- src/oldpool_func.h | 6 ++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/oldpool.h b/src/oldpool.h index 8396e5de07..5859571b54 100644 --- a/src/oldpool.h +++ b/src/oldpool.h @@ -211,6 +211,7 @@ struct PoolItem { /** * An overriden version of new that allocates memory on the pool. * @param size the size of the variable (unused) + * @pre CanAllocateItem() * @return the memory that is 'allocated' */ void *operator new(size_t size) @@ -282,7 +283,8 @@ private: protected: /** * Allocate a pool item; possibly allocate a new block in the pool. - * @return the allocated pool item (or NULL when the pool is full). + * @pre CanAllocateItem() + * @return the allocated pool item. */ static inline T *AllocateRaw() { @@ -292,7 +294,8 @@ protected: /** * Allocate a pool item; possibly allocate a new block in the pool. * @param first the first pool item to start searching - * @return the allocated pool item (or NULL when the pool is full). + * @pre CanAllocateItem() + * @return the allocated pool item. */ static inline T *AllocateRaw(uint &first) { @@ -342,7 +345,8 @@ public: OldMemoryPool _##name##_pool( \ #name, name##_POOL_MAX_BLOCKS, name##_POOL_BLOCK_SIZE_BITS, sizeof(type), \ PoolNewBlock, PoolCleanBlock); \ - template type *PoolItem::AllocateSafeRaw(uint &first); + template type *PoolItem::AllocateSafeRaw(uint &first); \ + template bool PoolItem::CanAllocateItem(uint count); #define STATIC_OLD_POOL(name, type, block_size_bits, max_blocks, new_block_proc, clean_block_proc) \ diff --git a/src/oldpool_func.h b/src/oldpool_func.h index 3fbed16a74..82b451617d 100644 --- a/src/oldpool_func.h +++ b/src/oldpool_func.h @@ -11,7 +11,8 @@ * Allocate a pool item; possibly allocate a new block in the pool. * @param first the first pool item to start searching * @pre first <= Tpool->GetSize() - * @return the allocated pool item (or NULL when the pool is full). + * @pre CanAllocateItem() + * @return the allocated pool item */ template *Tpool> T *PoolItem::AllocateSafeRaw(uint &first) { @@ -31,7 +32,8 @@ template *Tpool> T *PoolItemAddBlockToPool()) return AllocateRaw(first); - return NULL; + /* One should *ALWAYS* be sure to have enough space before making vehicles! */ + NOT_REACHED(); } /**