QNetworkAccessManager: protect more QElapsedTimer with isValid() checks

It might be redundant, but I can't definitely prove that these timers
are already started by the time we call elapsed() or restart() on them;
I "just" think they are because the CI is happy with the existing code,
even when adding assertions into QElapsedTimer.

As a precautionary measure, add more isValid() protections to QNAM code.
Also replace restart() with start() since the return value is unused.

Pick-to: 6.8 6.5
Change-Id: Ic64ab27116d8b1cb6c14e18dee79a15aa40844ce
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit dd7065616665e983349263bc5d600d764e164003)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Giuseppe D'Angelo 2025-03-17 11:12:11 +01:00 committed by Qt Cherry-pick Bot
parent 06b02f003e
commit 46c9c90ec4

View File

@ -126,8 +126,9 @@ void QNetworkReplyImplPrivate::_q_copyReadyRead()
// emit readyRead before downloadProgress in case this will cause events to be // emit readyRead before downloadProgress in case this will cause events to be
// processed and we get into a recursive call (as in QProgressDialog). // processed and we get into a recursive call (as in QProgressDialog).
emit q->readyRead(); emit q->readyRead();
if (downloadProgressSignalChoke.elapsed() >= progressSignalInterval) { if (downloadProgressSignalChoke.isValid() &&
downloadProgressSignalChoke.restart(); downloadProgressSignalChoke.elapsed() >= progressSignalInterval) {
downloadProgressSignalChoke.start();
emit q->downloadProgress(bytesDownloaded, totalSizeOpt.value_or(-1)); emit q->downloadProgress(bytesDownloaded, totalSizeOpt.value_or(-1));
} }
resumeNotificationHandling(); resumeNotificationHandling();
@ -491,8 +492,9 @@ void QNetworkReplyImplPrivate::appendDownstreamDataSignalEmissions()
emit q->readyRead(); emit q->readyRead();
// emit readyRead before downloadProgress in case this will cause events to be // emit readyRead before downloadProgress in case this will cause events to be
// processed and we get into a recursive call (as in QProgressDialog). // processed and we get into a recursive call (as in QProgressDialog).
if (downloadProgressSignalChoke.elapsed() >= progressSignalInterval) { if (downloadProgressSignalChoke.isValid() &&
downloadProgressSignalChoke.restart(); downloadProgressSignalChoke.elapsed() >= progressSignalInterval) {
downloadProgressSignalChoke.start();
emit q->downloadProgress(bytesDownloaded, totalSizeOpt.value_or(-1)); emit q->downloadProgress(bytesDownloaded, totalSizeOpt.value_or(-1));
} }
@ -580,8 +582,9 @@ void QNetworkReplyImplPrivate::appendDownstreamDataDownloadBuffer(qint64 bytesRe
// processed and we get into a recursive call (as in QProgressDialog). // processed and we get into a recursive call (as in QProgressDialog).
if (bytesDownloaded > 0) if (bytesDownloaded > 0)
emit q->readyRead(); emit q->readyRead();
if (downloadProgressSignalChoke.elapsed() >= progressSignalInterval) { if (downloadProgressSignalChoke.isValid() &&
downloadProgressSignalChoke.restart(); downloadProgressSignalChoke.elapsed() >= progressSignalInterval) {
downloadProgressSignalChoke.start();
emit q->downloadProgress(bytesDownloaded, bytesTotal); emit q->downloadProgress(bytesDownloaded, bytesTotal);
} }
} }