summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qbytearray.cpp
diff options
context:
space:
mode:
authorJoão Abecasis <joao.abecasis@nokia.com>2010-08-18 17:22:49 (GMT)
committerJoão Abecasis <joao.abecasis@nokia.com>2010-08-19 12:02:27 (GMT)
commit5e7e6788814549a1b60f9cc8972e03fb8a830d1c (patch)
treeda2f5bde4d37c291053f4584fa84de0fd48df4d6 /src/corelib/tools/qbytearray.cpp
parentc6cc767cb065ca77aba06fe15830c22f187e370c (diff)
downloadQt-5e7e6788814549a1b60f9cc8972e03fb8a830d1c.zip
Qt-5e7e6788814549a1b60f9cc8972e03fb8a830d1c.tar.gz
Qt-5e7e6788814549a1b60f9cc8972e03fb8a830d1c.tar.bz2
qUncompress: don't exit on allocation failure with -no-exceptions
If we're not allowed to fail here with -no-exceptions, we shouldn't throw either so just check the return value from qRealloc and be done with it. Also changed the test case so it doesn't expect bad_alloc being thrown; the test data now gets properly initialized... Reviewed-by: Olivier Goffart Reviewed-by: Harald Fernengel
Diffstat (limited to 'src/corelib/tools/qbytearray.cpp')
-rw-r--r--src/corelib/tools/qbytearray.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp
index 8d38e4c..3062c4a 100644
--- a/src/corelib/tools/qbytearray.cpp
+++ b/src/corelib/tools/qbytearray.cpp
@@ -542,12 +542,14 @@ QByteArray qUncompress(const uchar* data, int nbytes)
forever {
ulong alloc = len;
- d.reset(q_check_ptr(static_cast<QByteArray::Data *>(qRealloc(d.take(), sizeof(QByteArray::Data) + alloc))));
- if (!d) {
+ QByteArray::Data *p = static_cast<QByteArray::Data *>(qRealloc(d.data(), sizeof(QByteArray::Data) + alloc));
+ if (!p) {
// we are not allowed to crash here when compiling with QT_NO_EXCEPTIONS
qWarning("qUncompress: could not allocate enough memory to uncompress data");
return QByteArray();
}
+ d.take(); // realloc was successful
+ d.reset(p);
int res = ::uncompress((uchar*)d->array, &len,
(uchar*)data+4, nbytes-4);
@@ -555,12 +557,14 @@ QByteArray qUncompress(const uchar* data, int nbytes)
switch (res) {
case Z_OK:
if (len != alloc) {
- d.reset(q_check_ptr(static_cast<QByteArray::Data *>(qRealloc(d.take(), sizeof(QByteArray::Data) + len))));
- if (!d) {
+ QByteArray::Data *p = static_cast<QByteArray::Data *>(qRealloc(d.data(), sizeof(QByteArray::Data) + len));
+ if (!p) {
// we are not allowed to crash here when compiling with QT_NO_EXCEPTIONS
qWarning("qUncompress: could not allocate enough memory to uncompress data");
return QByteArray();
}
+ d.take(); // realloc was successful
+ d.reset(p);
}
d->ref = 1;
d->alloc = d->size = len;