summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2021-12-16 09:31:39 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-12-17 02:00:08 +0000
commit5085354e37672eec8313338de553db7e214fbdff (patch)
tree20404bcce304714e5a2459e16df8b67fd6771704 /tests
parentf1eac1f0f11b03b4b50b9d66821d193e349c8af7 (diff)
tst_QIODevice: fix UB (precondition violation) in SequentialReadBuffer::readData()
memcpy() mustn't be called with a nullptr, even if the size is zero. Fixes ubsan error: tst_qiodevice.cpp:561:15: runtime error: null pointer passed as argument 1, which is declared to never be null Even though ubsan only complained about one of them, fix all three occurrences of the pattern in the test. Change-Id: I5c06ab4a20a9e9f8831392c46c6969c05248fdac Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> (cherry picked from commit 572b55baa42787447643169811784bc64024fb5e) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp b/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp
index 0a4e3aefea..c58b49fc40 100644
--- a/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp
+++ b/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp
@@ -555,7 +555,8 @@ protected:
qint64 readData(char *data, qint64 maxSize) override
{
maxSize = qMin(maxSize, qint64(buf->size() - offset));
- memcpy(data, buf->constData() + offset, maxSize);
+ if (maxSize > 0)
+ memcpy(data, buf->constData() + offset, maxSize);
offset += maxSize;
return maxSize;
}
@@ -598,13 +599,15 @@ protected:
qint64 readData(char *data, qint64 maxSize) override
{
maxSize = qMin(maxSize, qint64(buf.size() - pos()));
- memcpy(data, buf.constData() + pos(), maxSize);
+ if (maxSize > 0)
+ memcpy(data, buf.constData() + pos(), maxSize);
return maxSize;
}
qint64 writeData(const char *data, qint64 maxSize) override
{
maxSize = qMin(maxSize, qint64(buf.size() - pos()));
- memcpy(buf.data() + pos(), data, maxSize);
+ if (maxSize > 0)
+ memcpy(buf.data() + pos(), data, maxSize);
return maxSize;
}