QUdpSocket: make sure receiveDatagram() returns empty on error
If the datagram reception failed, we forgot to set the buffer back to empty. The returned QNetworkDatagram did report isValid() == false, but it was possible to get the .data() and check its size, getting nonsense. Tests in the next commit. Change-Id: I638cf58bfa7b4e5fb386fffd14ea91adf2133d47 Reviewed-by: Jesus Fernandez <Jesus.Fernandez@qt.io> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>bb10
parent
e470348d87
commit
10f2b5aa66
|
|
@ -454,10 +454,12 @@ QNetworkDatagram QUdpSocket::receiveDatagram(qint64 maxSize)
|
|||
QAbstractSocketEngine::WantAll);
|
||||
d->hasPendingData = false;
|
||||
d->socketEngine->setReadNotificationEnabled(true);
|
||||
if (readBytes < 0)
|
||||
if (readBytes < 0) {
|
||||
d->setErrorAndEmit(d->socketEngine->error(), d->socketEngine->errorString());
|
||||
else if (readBytes != result.d->data.size())
|
||||
result.d->data.truncate(readBytes);
|
||||
readBytes = 0;
|
||||
}
|
||||
|
||||
result.d->data.truncate(readBytes);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue