Fix UB in QFileDevice::writeData()

Passing nullptr as the 2nd argument of memcpy
constitutes undefined behavior.

Fix by protecting the block with 'if (len)',
which, presumably, is the only valid case
where 'data' may be nullptr.

Change-Id: I7647d7e0808b1f26444ea3cf8bbf5cda9ddc9e6c
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
bb10
Marc Mutz 2016-01-06 13:31:11 +01:00
parent b4ab4868bc
commit 13189360e5
1 changed files with 1 additions and 1 deletions

View File

@ -560,7 +560,7 @@ qint64 QFileDevice::writeData(const char *data, qint64 len)
char *writePointer = d->writeBuffer.reserve(len);
if (len == 1)
*writePointer = *data;
else
else if (len)
::memcpy(writePointer, data, len);
return len;
}