From a52392241d8c83e652330dcbae8f5422f8bcf779 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 4 Jun 2018 22:48:17 +0300 Subject: [PATCH] Fix some possible crashes. --- Telegram/SourceFiles/app.cpp | 2 +- .../chat_helpers/stickers_list_widget.cpp | 15 +++++++++------ .../chat_helpers/stickers_list_widget.h | 6 +++--- Telegram/SourceFiles/mtproto/connection.cpp | 10 ++++++++-- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index d8c11cf4b4..43446958dc 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -678,7 +678,7 @@ namespace App { auto h = App::historyLoaded(chat->id); bool found = !h || !h->lastKeyboardFrom; auto botStatus = -1; - for (auto i = chat->participants.begin(), e = chat->participants.end(); i != e;) { + for (auto i = chat->participants.begin(); i != chat->participants.end();) { auto [user, version] = *i; if (version < pversion) { i = chat->participants.erase(i); diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index 8e2b48cca3..fa34f44be8 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -932,7 +932,7 @@ void StickersListWidget::refreshSearchRows() { } void StickersListWidget::refreshSearchRows( - const std::vector *cloudSets) { + const std::vector *cloudSets) { clearSelection(); _searchSets.clear(); @@ -997,9 +997,12 @@ void StickersListWidget::fillLocalSearchRows(const QString &query) { } void StickersListWidget::fillCloudSearchRows( - const std::vector &sets) { - for (const auto set : sets) { - addSearchRow(set); + const std::vector &cloudSets) { + const auto &sets = Auth().data().stickerSets(); + for (const auto setId : cloudSets) { + if (const auto it = sets.find(setId); it != sets.end()) { + addSearchRow(&*it); + } } } @@ -1049,7 +1052,7 @@ void StickersListWidget::searchResultsDone( if (it == _searchCache.cend()) { it = _searchCache.emplace( _searchQuery, - std::vector()).first; + std::vector()).first; } auto &d = result.c_messages_foundStickerSets(); for_const (const auto &stickerSet, d.vsets.v) { @@ -1084,7 +1087,7 @@ void StickersListWidget::searchResultsDone( if (set->stickers.empty() && set->covers.empty()) { continue; } - it->second.push_back(set); + it->second.push_back(set->id); } } showSearchResults(); diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h index fc67a24d6f..928606794b 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h @@ -243,9 +243,9 @@ private: void showSearchResults(); void searchResultsDone(const MTPmessages_FoundStickerSets &result); void refreshSearchRows(); - void refreshSearchRows(const std::vector *cloudSets); + void refreshSearchRows(const std::vector *cloudSets); void fillLocalSearchRows(const QString &query); - void fillCloudSearchRows(const std::vector &sets); + void fillCloudSearchRows(const std::vector &cloudSets); void addSearchRow(not_null set); ChannelData *_megagroupSet = nullptr; @@ -284,7 +284,7 @@ private: QTimer _previewTimer; bool _previewShown = false; - std::map> _searchCache; + std::map> _searchCache; std::vector> _searchIndex; base::Timer _searchRequestTimer; QString _searchQuery, _searchNextQuery; diff --git a/Telegram/SourceFiles/mtproto/connection.cpp b/Telegram/SourceFiles/mtproto/connection.cpp index 4c24550c7c..021cecf59e 100644 --- a/Telegram/SourceFiles/mtproto/connection.cpp +++ b/Telegram/SourceFiles/mtproto/connection.cpp @@ -1261,11 +1261,17 @@ void ConnectionPrivate::markConnectionOld() { void ConnectionPrivate::sendPingByTimer() { if (_pingId) { - if (_pingSendAt + kPingSendAfterForce - kPingSendAfter - TimeMs(1000) < getms(true)) { + // _pingSendAt: when to send next ping (lastPingAt + kPingSendAfter) + // could be equal to zero. + const auto now = getms(true); + const auto mustSendTill = _pingSendAt + + kPingSendAfterForce + - kPingSendAfter; + if (mustSendTill < now + 1000) { LOG(("Could not send ping for some seconds, restarting...")); return restart(); } else { - _pingSender.callOnce(_pingSendAt + kPingSendAfterForce - kPingSendAfter - getms(true)); + _pingSender.callOnce(mustSendTill - now); } } else { emit needToSendAsync();