diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2016-12-12 11:39:38 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2016-12-14 14:33:11 +0000 |
commit | 1f665efa913bf55f215ceff27ebfc9f0e0769aee (patch) | |
tree | f97d164adbfecf2501cd7bcd7c3a96618d7ca8a8 /src | |
parent | b8fab7c9f5debec9e26816b6b9581de921f90ef6 (diff) |
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>
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/painting/qdatabuffer_p.h | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/gui/painting/qdatabuffer_p.h b/src/gui/painting/qdatabuffer_p.h index 77b5be0c4c..7cac2ac358 100644 --- a/src/gui/painting/qdatabuffer_p.h +++ b/src/gui/painting/qdatabuffer_p.h @@ -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; } |