aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/array.h4
-rw-r--r--common/list.h1
-rw-r--r--common/str.cpp10
3 files changed, 11 insertions, 4 deletions
diff --git a/common/array.h b/common/array.h
index 7ac08efa92..ace5ce7e4b 100644
--- a/common/array.h
+++ b/common/array.h
@@ -54,6 +54,7 @@ public:
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 @@ public:
Array(const T2 *data, int n) {
_capacity = _size = n;
_storage = new T[_capacity];
+ assert(_storage);
copy(data, data + _size, _storage);
}
@@ -149,6 +151,7 @@ public:
_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 @@ public:
T *old_storage = _storage;
_capacity = newCapacity;
_storage = new T[newCapacity];
+ assert(_storage);
if (old_storage) {
// Copy old data
diff --git a/common/list.h b/common/list.h
index 4b5d95df0d..f3bc1df35e 100644
--- a/common/list.h
+++ b/common/list.h
@@ -247,6 +247,7 @@ protected:
*/
void insert(NodeBase *pos, const t_T &element) {
ListInternal::NodeBase *newNode = new Node(element);
+ assert(newNode);
newNode->_next = pos;
newNode->_prev = pos->_prev;
diff --git a/common/str.cpp b/common/str.cpp
index 10d258e058..abe0ab6650 100644
--- a/common/str.cpp
+++ b/common/str.cpp
@@ -79,7 +79,7 @@ void String::initWithCStr(const char *str, uint32 len) {
// 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 @@ void String::ensureCapacity(uint32 new_size, bool keep_old) {
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::ensureCapacity(uint32 new_size, bool keep_old) {
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 @@ void String::decRefCount(int *oldRefCount) {
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