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. Pick-to: 6.3 6.2 5.15 Change-Id: I5c06ab4a20a9e9f8831392c46c6969c05248fdac Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
b1938e5787
commit
572b55baa4
@ -558,6 +558,7 @@ protected:
|
||||
qint64 readData(char *data, qint64 maxSize) override
|
||||
{
|
||||
maxSize = qMin(maxSize, qint64(buf->size() - offset));
|
||||
if (maxSize > 0)
|
||||
memcpy(data, buf->constData() + offset, maxSize);
|
||||
offset += maxSize;
|
||||
return maxSize;
|
||||
@ -601,12 +602,14 @@ protected:
|
||||
qint64 readData(char *data, qint64 maxSize) override
|
||||
{
|
||||
maxSize = qMin(maxSize, qint64(buf.size() - pos()));
|
||||
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()));
|
||||
if (maxSize > 0)
|
||||
memcpy(buf.data() + pos(), data, maxSize);
|
||||
return maxSize;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user