From e3c6abfc3db5e002cefcc19f45b614ffb4f16085 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 10 May 2018 14:56:36 +0300 Subject: [PATCH] Fix possible crash in reply returns. --- .../SourceFiles/history/history_widget.cpp | 20 +++++++++++++------ .../SourceFiles/mtproto/connection_http.cpp | 6 +++--- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index ad218f9f3..16b15f27e 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -1558,7 +1558,9 @@ void HistoryWidget::calcNextReplyReturn() { _replyReturn = App::histItemById(_channel, _replyReturns.back()); } } - if (!_replyReturn) updateControlsVisibility(); + if (!_replyReturn) { + updateControlsVisibility(); + } } void HistoryWidget::fastShowAtEnd(not_null history) { @@ -1659,11 +1661,13 @@ void HistoryWidget::showHistory(const PeerId &peerId, MsgId showAtMsgId, bool re } clearDelayedShowAt(); - if (_replyReturn) { + while (_replyReturn) { if (_replyReturn->history() == _history && _replyReturn->id == showAtMsgId) { calcNextReplyReturn(); } else if (_replyReturn->history() == _migrated && -_replyReturn->id == showAtMsgId) { calcNextReplyReturn(); + } else { + break; } } @@ -2431,11 +2435,15 @@ void HistoryWidget::messagesReceived(PeerData *peer, const MTPmessages_Messages return; } } - if (_replyReturn) { - if (_replyReturn->history() == _history && _replyReturn->id == _delayedShowAtMsgId) { + while (_replyReturn) { + if (_replyReturn->history() == _history + && _replyReturn->id == _delayedShowAtMsgId) { calcNextReplyReturn(); - } else if (_replyReturn->history() == _migrated && -_replyReturn->id == _delayedShowAtMsgId) { + } else if (_replyReturn->history() == _migrated + && -_replyReturn->id == _delayedShowAtMsgId) { calcNextReplyReturn(); + } else { + break; } } @@ -4615,7 +4623,7 @@ void HistoryWidget::itemRemoved(not_null item) { cancelReply(); } } - if (item == _replyReturn) { + while (item == _replyReturn) { calcNextReplyReturn(); } if (_pinnedBar && item->id == _pinnedBar->msgId) { diff --git a/Telegram/SourceFiles/mtproto/connection_http.cpp b/Telegram/SourceFiles/mtproto/connection_http.cpp index 1bf154e6e..723e17b53 100644 --- a/Telegram/SourceFiles/mtproto/connection_http.cpp +++ b/Telegram/SourceFiles/mtproto/connection_http.cpp @@ -46,9 +46,9 @@ qint32 HTTPConnection::handleError(QNetworkReply *reply) { // returnes "maybe ba switch (reply->error()) { case QNetworkReply::ConnectionRefusedError: LOG(("HTTP Error: connection refused - %1").arg(reply->errorString())); break; case QNetworkReply::RemoteHostClosedError: LOG(("HTTP Error: remote host closed - %1").arg(reply->errorString())); break; - case QNetworkReply::HostNotFoundError: LOG(("HTTP Error: host not found - %2").arg(reply->error()).arg(reply->errorString())); break; - case QNetworkReply::TimeoutError: LOG(("HTTP Error: timeout - %2").arg(reply->error()).arg(reply->errorString())); break; - case QNetworkReply::OperationCanceledError: LOG(("HTTP Error: cancelled - %2").arg(reply->error()).arg(reply->errorString())); break; + case QNetworkReply::HostNotFoundError: LOG(("HTTP Error: host not found - %1").arg(reply->errorString())); break; + case QNetworkReply::TimeoutError: LOG(("HTTP Error: timeout - %1").arg(reply->errorString())); break; + case QNetworkReply::OperationCanceledError: LOG(("HTTP Error: cancelled - %1").arg(reply->errorString())); break; case QNetworkReply::SslHandshakeFailedError: case QNetworkReply::TemporaryNetworkFailureError: case QNetworkReply::NetworkSessionFailedError: