summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qbitarray.cpp
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@digia.com>2013-05-30 14:51:18 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-06-05 10:46:51 +0200
commit9aa24645eb09be9e1d05060b2d976327726cb747 (patch)
tree2e692b3b006240a554425f310d00324f894a5241 /src/corelib/tools/qbitarray.cpp
parentf36374727e5445cdab489a27605c35d1c4515317 (diff)
Prevent negative size in QBitArray, QVector and QVarLengthArray ctors.
As shown in QTBUG-24345, QBitArray will exhibit invalid reads when initialised with a negative size and run under valgrind. QVector and QVarLengthArray both cause a crash if initialised with a negative size. This patch enforces sizes greater than or equal to 0 with asserts and existing if statements, and hence impose no performance penalty for release builds. Task-number: QTBUG-24345 Task-number: QTBUG-30037 Change-Id: I9a969f6016e0a59904a60bbfe9e5360e6f523b87 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qbitarray.cpp')
-rw-r--r--src/corelib/tools/qbitarray.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/corelib/tools/qbitarray.cpp b/src/corelib/tools/qbitarray.cpp
index 2b459b2b1b..b04c4f9c3d 100644
--- a/src/corelib/tools/qbitarray.cpp
+++ b/src/corelib/tools/qbitarray.cpp
@@ -122,7 +122,8 @@ QT_BEGIN_NAMESPACE
*/
QBitArray::QBitArray(int size, bool value)
{
- if (!size) {
+ Q_ASSERT_X(size >= 0, "QBitArray::QBitArray", "Size must be greater than or equal to 0.");
+ if (size <= 0) {
d.resize(0);
return;
}