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
parent
b8fab7c9f5
commit
1f665efa91
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue