Q_CHECK_PTR the result of QDataBuffer's allocations

We might run out of memory or malloc() or realloc() might fail for any
other reason. We want to crash cleanly with a clear message in that
case, rather than returning a null pointer.

Change-Id: If09c1b9e905fc60a5d9d45e598a418df433cf83b
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Ulf Hermann 2016-12-12 11:39:38 +01:00
parent b8fab7c9f5
commit 1f665efa91
1 changed files with 8 additions and 4 deletions

View File

@ -65,10 +65,12 @@ public:
QDataBuffer(int res)
{
capacity = res;
if (res)
if (res) {
buffer = (Type*) malloc(capacity * sizeof(Type));
else
Q_CHECK_PTR(buffer);
} else {
buffer = 0;
}
siz = 0;
}
@ -115,14 +117,16 @@ public:
while (capacity < size)
capacity *= 2;
buffer = (Type*) realloc(buffer, capacity * sizeof(Type));
Q_CHECK_PTR(buffer);
}
}
inline void shrink(int size) {
capacity = size;
if (size)
if (size) {
buffer = (Type*) realloc(buffer, capacity * sizeof(Type));
else {
Q_CHECK_PTR(buffer);
} else {
free(buffer);
buffer = 0;
}