diff options
author | Marc Mutz <marc.mutz@qt.io> | 2023-03-02 19:45:04 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2023-03-17 00:41:33 +0100 |
commit | 96dc4acb235f13a72bef7c719d005846fe1d9726 (patch) | |
tree | a155d559e276d9878755f9c3cb9f5133a2dcb06e /tests/auto/corelib/tools | |
parent | e80fc16ceccd45f862a5b9d728a52cab60c4380b (diff) |
QCryptographicHash: check addData() with null QByteArrayView
When this code was using QByteArray, whose data() is never nullptr,
the strings presented to the underlying C APIs were always valid NTSs
(nullptr is not a valid NTS).
With QByteArrayView, or with QT5_NULL_STRINGS != 1, this is no longer
the case. Check that all implementations are fine with that.
Pick-to: 6.5 6.4
Change-Id: I78251288a4784440af4a2daf095aed7c53867287
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'tests/auto/corelib/tools')
-rw-r--r-- | tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp b/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp index 2a0fd1a7c1..a7c22ffe29 100644 --- a/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp +++ b/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp @@ -31,6 +31,8 @@ private slots: void files(); void hashLength_data(); void hashLength(); + void addDataAcceptsNullByteArrayView_data() { hashLength_data(); } + void addDataAcceptsNullByteArrayView(); void move(); void swap(); // keep last @@ -414,6 +416,27 @@ void tst_QCryptographicHash::hashLength() QCOMPARE(QCryptographicHash::hashLength(algorithm), expectedSize); } +void tst_QCryptographicHash::addDataAcceptsNullByteArrayView() +{ + QFETCH(const QCryptographicHash::Algorithm, algorithm); + + if (!QCryptographicHash::supportsAlgorithm(algorithm)) + QSKIP("QCryptographicHash doesn't support this algorithm"); + + QCryptographicHash hash1(algorithm); + hash1.addData("meep"); + hash1.addData(QByteArrayView{}); // after other data + + QCryptographicHash hash2(algorithm); + hash2.addData(QByteArrayView{}); // before any other data + hash2.addData("meep"); + + const auto expected = QCryptographicHash::hash("meep", algorithm); + + QCOMPARE(hash1.resultView(), expected); + QCOMPARE(hash2.resultView(), expected); +} + void tst_QCryptographicHash::move() { QCryptographicHash hash1(QCryptographicHash::Sha1); |