summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2014-03-18 16:43:36 -0700
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-04-04 19:32:21 +0200
commit964ac38fb0dc84e05606b3abf6f7fcb887a62528 (patch)
tree8156877416e9b603391079cf9c5f29c6c3ad75d2 /tests/auto
parent8c0919a2863948ed8705893c574b481dcdc30ff2 (diff)
Don't read before the beginning of the string
The code did discard the the data, so it wasn't affecting the comparison result (tests added anyway), but it could cause crashes if the pointer to the beginning of the data in the first 8 bytes of a page. Change-Id: I618e68de329b65de34ef8c934934c3e631cc6c9f Reported-By: Erik Verbruggen Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/tools/qstringref/tst_qstringref.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp b/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp
index 7bbcee8ab2..342abb7ea8 100644
--- a/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp
+++ b/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp
@@ -68,6 +68,8 @@ private slots:
void isEmpty();
void compare_data();
void compare();
+ void compare2_data();
+ void compare2();
void operator_eqeq_nullstring();
void toNum();
void toDouble_data();
@@ -792,11 +794,17 @@ void tst_QStringRef::compare_data()
QTest::newRow("data3") << QString("abc") << QString("abc") << 0 << 0;
QTest::newRow("data4") << QString("abC") << QString("abc") << -1 << 0;
QTest::newRow("data5") << QString("abc") << QString("abC") << 1 << 0;
+ QTest::newRow("data10") << QString("abcdefgh") << QString("abcdefgh") << 0 << 0;
+ QTest::newRow("data11") << QString("abcdefgh") << QString("abCdefgh") << 1 << 0;
+ QTest::newRow("data12") << QString("0123456789012345") << QString("0123456789012345") << 0 << 0;
+ QTest::newRow("data13") << QString("0123556789012345") << QString("0123456789012345") << 1 << 1;
// different length
QTest::newRow("data6") << QString("abcdef") << QString("abc") << 1 << 1;
QTest::newRow("data7") << QString("abCdef") << QString("abc") << -1 << 1;
QTest::newRow("data8") << QString("abc") << QString("abcdef") << -1 << -1;
+ QTest::newRow("data14") << QString("abcdefgh") << QString("abcdefghi") << -1 << -1;
+ QTest::newRow("data15") << QString("01234567890123456") << QString("0123456789012345") << 1 << 1;
QString upper;
upper += QChar(QChar::highSurrogate(0x10400));
@@ -862,6 +870,46 @@ void tst_QStringRef::compare()
}
}
+void tst_QStringRef::compare2_data()
+{
+ compare_data();
+}
+
+void tst_QStringRef::compare2()
+{
+ QFETCH(QString, s1);
+ QFETCH(QString, s2);
+ QFETCH(int, csr);
+ QFETCH(int, cir);
+
+ // prepend and append data
+ // we only use Latin1 here so isLatin1 still results true
+ s1.prepend("xyz").append("zyx");
+ s2.prepend("foobar").append("raboof");
+
+ QStringRef r1(&s1, 3, s1.length() - 6);
+ QStringRef r2(&s2, 6, s2.length() - 12);
+
+ QCOMPARE(sign(QStringRef::compare(r1, r2)), csr);
+ QCOMPARE(sign(r1.compare(r2)), csr);
+
+ QCOMPARE(sign(r1.compare(r2, Qt::CaseSensitive)), csr);
+ QCOMPARE(sign(r1.compare(r2, Qt::CaseInsensitive)), cir);
+
+ QCOMPARE(sign(QStringRef::compare(r1, r2, Qt::CaseSensitive)), csr);
+ QCOMPARE(sign(QStringRef::compare(r1, r2, Qt::CaseInsensitive)), cir);
+
+ if (isLatin(s2)) {
+ QCOMPARE(sign(QStringRef::compare(r1, QLatin1String(r2.toLatin1()))), csr);
+ QCOMPARE(sign(QStringRef::compare(r1, QLatin1String(r2.toLatin1()), Qt::CaseInsensitive)), cir);
+ }
+
+ if (isLatin(s1)) {
+ QCOMPARE(sign(QStringRef::compare(r2, QLatin1String(r1.toLatin1()))), -csr);
+ QCOMPARE(sign(QStringRef::compare(r2, QLatin1String(r1.toLatin1()), Qt::CaseInsensitive)), -cir);
+ }
+}
+
void tst_QStringRef::toNum()
{
#define TEST_TO_INT(num, func, type) \