From 1588f0d687d0c3510d4511bd9a5a78b06b898cef Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 18 Jan 2023 17:10:08 +0300 Subject: [PATCH] Return after call to on_error. --- td/mtproto/TlsInit.cpp | 10 ++++++---- td/telegram/MessagesManager.cpp | 6 +++--- td/telegram/Premium.cpp | 6 +++--- td/telegram/StickersManager.cpp | 7 +++---- td/telegram/files/FileManager.cpp | 6 ++---- tdnet/td/net/TransparentProxy.cpp | 6 +++--- tdutils/td/utils/StringBuilder.h | 2 +- 7 files changed, 21 insertions(+), 22 deletions(-) diff --git a/td/mtproto/TlsInit.cpp b/td/mtproto/TlsInit.cpp index c03b3cda7..b5b181a33 100644 --- a/td/mtproto/TlsInit.cpp +++ b/td/mtproto/TlsInit.cpp @@ -263,11 +263,14 @@ class TlsHelloCalcLength { } Result finish() { + if (status_.is_error()) { + return std::move(status_); + } if (size_ > 514) { - on_error(Status::Error("Too long for zero padding")); + return Status::Error("Too long for zero padding"); } if (size_ < 11 + 32) { - on_error(Status::Error("Too small for hash")); + return Status::Error("Too small for hash"); } int zero_pad = 515 - static_cast(size_); using Op = TlsHello::Op; @@ -275,9 +278,8 @@ class TlsHelloCalcLength { do_op(Op::zero(zero_pad), nullptr); do_op(Op::end_scope(), nullptr); if (!scope_offset_.empty()) { - on_error(Status::Error("Unbalanced scopes")); + return Status::Error("Unbalanced scopes"); } - TRY_STATUS(std::move(status_)); return size_; } diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 824ccbca5..3e92186cf 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -1684,7 +1684,7 @@ class SaveDraftMessageQuery final : public Td::ResultHandler { bool result = result_ptr.ok(); if (!result) { - on_error(Status::Error(400, "Save draft failed")); + return on_error(Status::Error(400, "Save draft failed")); } promise_.set_value(Unit()); @@ -1761,7 +1761,7 @@ class ToggleDialogPinQuery final : public Td::ResultHandler { bool result = result_ptr.ok(); if (!result) { - on_error(Status::Error(400, "Toggle dialog pin failed")); + return on_error(Status::Error(400, "Toggle dialog pin failed")); } promise_.set_value(Unit()); @@ -1849,7 +1849,7 @@ class ToggleDialogUnreadMarkQuery final : public Td::ResultHandler { bool result = result_ptr.ok(); if (!result) { - on_error(Status::Error(400, "Toggle dialog mark failed")); + return on_error(Status::Error(400, "Toggle dialog mark failed")); } promise_.set_value(Unit()); diff --git a/td/telegram/Premium.cpp b/td/telegram/Premium.cpp index 2c2215898..88474388f 100644 --- a/td/telegram/Premium.cpp +++ b/td/telegram/Premium.cpp @@ -199,10 +199,10 @@ class CanPurchasePremiumQuery final : public Td::ResultHandler { } bool result = result_ptr.ok(); - if (result) { - return promise_.set_value(Unit()); + if (!result) { + return on_error(Status::Error(400, "Premium can't be purchased")); } - on_error(Status::Error(400, "Premium can't be purchased")); + promise_.set_value(Unit()); } void on_error(Status status) final { diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index c404e1bb3..591eef085 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -864,11 +864,10 @@ class ReloadSpecialStickerSetQuery final : public Td::ResultHandler { td_->stickers_manager_->on_get_messages_sticker_set(sticker_set_id_, std::move(set_ptr), false, "ReloadSpecialStickerSetQuery"); } - if (sticker_set_id_.is_valid()) { - td_->stickers_manager_->on_get_special_sticker_set(type_, sticker_set_id_); - } else { - on_error(Status::Error(500, "Failed to add special sticker set")); + if (!sticker_set_id_.is_valid()) { + return on_error(Status::Error(500, "Failed to add special sticker set")); } + td_->stickers_manager_->on_get_special_sticker_set(type_, sticker_set_id_); } void on_error(Status status) final { diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index a6a4de45e..6bd112bca 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -2446,8 +2446,7 @@ void FileManager::run_download(FileNodePtr node, bool force_update_priority) { QueryId query_id = queries_container_.create(Query{file_id, Query::Type::DownloadWaitFileReference}); node->download_id_ = query_id; if (node->download_was_update_file_reference_) { - on_error(query_id, Status::Error("Can't download file: have no valid file reference")); - return; + return on_error(query_id, Status::Error("Can't download file: have no valid file reference")); } node->download_was_update_file_reference_ = true; @@ -2951,8 +2950,7 @@ void FileManager::run_upload(FileNodePtr node, vector bad_parts) { QueryId query_id = queries_container_.create(Query{file_id, Query::Type::UploadWaitFileReference}); node->upload_id_ = query_id; if (node->upload_was_update_file_reference_) { - on_error(query_id, Status::Error("Can't upload file: have no valid file reference")); - return; + return on_error(query_id, Status::Error("Can't upload file: have no valid file reference")); } node->upload_was_update_file_reference_ = true; diff --git a/tdnet/td/net/TransparentProxy.cpp b/tdnet/td/net/TransparentProxy.cpp index 96d4bd8a4..025c0ca28 100644 --- a/tdnet/td/net/TransparentProxy.cpp +++ b/tdnet/td/net/TransparentProxy.cpp @@ -67,14 +67,14 @@ void TransparentProxy::loop() { TRY_STATUS(fd_.flush_read()); TRY_STATUS(loop_impl()); TRY_STATUS(fd_.flush_write()); + if (can_close_local(fd_)) { + return Status::Error("Connection closed"); + } return Status::OK(); }(); if (status.is_error()) { on_error(std::move(status)); } - if (can_close_local(fd_)) { - on_error(Status::Error("Connection closed")); - } } void TransparentProxy::timeout_expired() { diff --git a/tdutils/td/utils/StringBuilder.h b/tdutils/td/utils/StringBuilder.h index 3bd40574a..fcf5016bf 100644 --- a/tdutils/td/utils/StringBuilder.h +++ b/tdutils/td/utils/StringBuilder.h @@ -35,7 +35,7 @@ class StringBuilder { void push_back(char c) { if (unlikely(end_ptr_ <= current_ptr_)) { if (!reserve_inner(RESERVED_SIZE)) { - on_error(); + error_flag_ = true; return; } }