[Scummvm-cvs-logs] SF.net SVN: scummvm:[40291] scummvm/trunk/common
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Mon May 4 00:45:31 CEST 2009
Revision: 40291
http://scummvm.svn.sourceforge.net/scummvm/?rev=40291&view=rev
Author: fingolfin
Date: 2009-05-03 22:45:31 +0000 (Sun, 03 May 2009)
Log Message:
-----------
COMMON: Check for failed memory allocations; changed Common::String to use new/delete instead of malloc/free
Modified Paths:
--------------
scummvm/trunk/common/array.h
scummvm/trunk/common/list.h
scummvm/trunk/common/str.cpp
Modified: scummvm/trunk/common/array.h
===================================================================
--- scummvm/trunk/common/array.h 2009-05-03 22:45:13 UTC (rev 40290)
+++ scummvm/trunk/common/array.h 2009-05-03 22:45:31 UTC (rev 40291)
@@ -54,6 +54,7 @@
Array(const Array<T> &array) : _capacity(0), _size(0), _storage(0) {
_capacity = _size = array._size;
_storage = new T[_capacity];
+ assert(_storage);
copy(array._storage, array._storage + _size, _storage);
}
@@ -64,6 +65,7 @@
Array(const T2 *data, int n) {
_capacity = _size = n;
_storage = new T[_capacity];
+ assert(_storage);
copy(data, data + _size, _storage);
}
@@ -149,6 +151,7 @@
_size = array._size;
_capacity = _size + 32;
_storage = new T[_capacity];
+ assert(_storage);
copy(array._storage, array._storage + _size, _storage);
return *this;
@@ -193,6 +196,7 @@
T *old_storage = _storage;
_capacity = newCapacity;
_storage = new T[newCapacity];
+ assert(_storage);
if (old_storage) {
// Copy old data
Modified: scummvm/trunk/common/list.h
===================================================================
--- scummvm/trunk/common/list.h 2009-05-03 22:45:13 UTC (rev 40290)
+++ scummvm/trunk/common/list.h 2009-05-03 22:45:31 UTC (rev 40291)
@@ -247,6 +247,7 @@
*/
void insert(NodeBase *pos, const t_T &element) {
ListInternal::NodeBase *newNode = new Node(element);
+ assert(newNode);
newNode->_next = pos;
newNode->_prev = pos->_prev;
Modified: scummvm/trunk/common/str.cpp
===================================================================
--- scummvm/trunk/common/str.cpp 2009-05-03 22:45:13 UTC (rev 40290)
+++ scummvm/trunk/common/str.cpp 2009-05-03 22:45:31 UTC (rev 40291)
@@ -79,7 +79,7 @@
// Not enough internal storage, so allocate more
_extern._capacity = computeCapacity(len+1);
_extern._refCount = 0;
- _str = (char *)malloc(_extern._capacity);
+ _str = new char[_extern._capacity];
assert(_str != 0);
}
@@ -159,7 +159,7 @@
newCapacity = MAX(curCapacity * 2, computeCapacity(new_size+1));
// Allocate new storage
- newStorage = (char *)malloc(newCapacity);
+ newStorage = new char[newCapacity];
assert(newStorage);
}
@@ -190,8 +190,10 @@
void String::incRefCount() const {
assert(!isStorageIntern());
if (_extern._refCount == 0) {
- if (g_refCountPool == 0)
+ if (g_refCountPool == 0) {
g_refCountPool = new MemoryPool(sizeof(int));
+ assert(g_refCountPool);
+ }
_extern._refCount = (int *)g_refCountPool->allocChunk();
*_extern._refCount = 2;
@@ -214,7 +216,7 @@
assert(g_refCountPool);
g_refCountPool->freeChunk(oldRefCount);
}
- free(_str);
+ delete _str;
// Even though _str points to a freed memory block now,
// we do not change its value, because any code that calls
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list