diff options
author | Leonard Lee <leonard.lee@digia.com> | 2013-08-19 09:13:55 (GMT) |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-08-30 08:47:30 (GMT) |
commit | ab4035d522eede6e6fb9251b521ab9e030fa13e3 (patch) | |
tree | 49670a6b02ccf5685d086a7efc50c4bca3a39686 | |
parent | 764f1a51209212b6fc60cef5c12e9748d06b57de (diff) | |
download | Qt-ab4035d522eede6e6fb9251b521ab9e030fa13e3.zip Qt-ab4035d522eede6e6fb9251b521ab9e030fa13e3.tar.gz Qt-ab4035d522eede6e6fb9251b521ab9e030fa13e3.tar.bz2 |
Add Q_ASSERT in qAllocMore() function.
The negative range test is no longer needed in QByteArray's autotest.
Task-number: QTBUG-33038
Change-Id: I4d77e78e485b3b64a31dffd99b9fe2c14420d0a2
(partial cherry picked from qtbase commit fb8be9905d5f3216edc3fbb72b8ce1c380737eac)
(partial cherry picked from qtbase commit 0ed3cf2a1c487387bbc958317c791c9c53cf5a16)
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r-- | src/corelib/tools/qbytearray.cpp | 3 | ||||
-rw-r--r-- | tests/auto/qbytearray/tst_qbytearray.cpp | 4 |
2 files changed, 4 insertions, 3 deletions
diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index 121f45f..b91b0f2 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -69,6 +69,9 @@ int qFindByteArray( int qAllocMore(int alloc, int extra) { + Q_ASSERT(alloc >= 0 && extra >= 0); + Q_ASSERT_X(alloc < (1 << 30) - extra, "qAllocMore", "Requested size is too large!"); + if (alloc == 0 && extra == 0) return 0; const int page = 1 << 12; diff --git a/tests/auto/qbytearray/tst_qbytearray.cpp b/tests/auto/qbytearray/tst_qbytearray.cpp index 1363dbf..e63a0aba 100644 --- a/tests/auto/qbytearray/tst_qbytearray.cpp +++ b/tests/auto/qbytearray/tst_qbytearray.cpp @@ -1116,9 +1116,7 @@ void tst_QByteArray::toULongLong() void tst_QByteArray::qAllocMore() { static const int t[] = { - INT_MIN, INT_MIN + 1, -1234567, -66000, -1025, - -3, -1, 0, +1, +3, +1025, +66000, +1234567, INT_MAX - 1, INT_MAX, - INT_MAX/3 + 0, +1, +3, +1025, +66000, +1234567, INT_MAX/4 }; static const int N = sizeof(t)/sizeof(t[0]); |