From 542271a1fdbb6aa34c868d48fb4cc5ba9e002635 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 12 Dec 2023 23:20:41 +0300 Subject: [PATCH] Don't save get_id() to a used-once variable before switch. --- td/telegram/ContactsManager.cpp | 12 ++++-------- td/telegram/DraftMessage.cpp | 3 +-- td/telegram/MessageContent.cpp | 3 +-- td/telegram/ReplyMarkup.cpp | 6 ++---- td/telegram/StoryContent.cpp | 3 +-- td/telegram/StoryManager.cpp | 3 +-- 6 files changed, 10 insertions(+), 20 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 504bd114b..1a5a16fc3 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -3398,8 +3398,7 @@ class GetCreatedPublicChannelsQuery final : public Td::ResultHandler { auto chats_ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for GetCreatedPublicChannelsQuery: " << to_string(chats_ptr); - int32 constructor_id = chats_ptr->get_id(); - switch (constructor_id) { + switch (chats_ptr->get_id()) { case telegram_api::messages_chats::ID: { auto chats = move_tl_object_as(chats_ptr); td_->contacts_manager_->on_get_created_public_channels(type_, std::move(chats->chats_)); @@ -3442,8 +3441,7 @@ class GetGroupsForDiscussionQuery final : public Td::ResultHandler { auto chats_ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for GetGroupsForDiscussionQuery: " << to_string(chats_ptr); - int32 constructor_id = chats_ptr->get_id(); - switch (constructor_id) { + switch (chats_ptr->get_id()) { case telegram_api::messages_chats::ID: { auto chats = move_tl_object_as(chats_ptr); td_->contacts_manager_->on_get_dialogs_for_discussion(std::move(chats->chats_)); @@ -3622,8 +3620,7 @@ class GetChatsQuery final : public Td::ResultHandler { } auto chats_ptr = result_ptr.move_as_ok(); - int32 constructor_id = chats_ptr->get_id(); - switch (constructor_id) { + switch (chats_ptr->get_id()) { case telegram_api::messages_chats::ID: { auto chats = move_tl_object_as(chats_ptr); td_->contacts_manager_->on_get_chats(std::move(chats->chats_), "GetChatsQuery"); @@ -3707,8 +3704,7 @@ class GetChannelsQuery final : public Td::ResultHandler { // LOG(INFO) << "Receive result for GetChannelsQuery: " << to_string(result_ptr.ok()); auto chats_ptr = result_ptr.move_as_ok(); - int32 constructor_id = chats_ptr->get_id(); - switch (constructor_id) { + switch (chats_ptr->get_id()) { case telegram_api::messages_chats::ID: { auto chats = move_tl_object_as(chats_ptr); td_->contacts_manager_->on_get_chats(std::move(chats->chats_), "GetChannelsQuery"); diff --git a/td/telegram/DraftMessage.cpp b/td/telegram/DraftMessage.cpp index fc086950f..c4d849c53 100644 --- a/td/telegram/DraftMessage.cpp +++ b/td/telegram/DraftMessage.cpp @@ -264,8 +264,7 @@ unique_ptr get_draft_message(Td *td, if (draft_message_ptr == nullptr) { return nullptr; } - auto constructor_id = draft_message_ptr->get_id(); - switch (constructor_id) { + switch (draft_message_ptr->get_id()) { case telegram_api::draftMessageEmpty::ID: return nullptr; case telegram_api::draftMessage::ID: diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index b21fba4ed..27d5bdc73 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -5550,8 +5550,7 @@ unique_ptr get_message_content(Td *td, FormattedText message, *disable_web_page_preview = false; } - int32 constructor_id = media_ptr == nullptr ? telegram_api::messageMediaEmpty::ID : media_ptr->get_id(); - switch (constructor_id) { + switch (media_ptr == nullptr ? telegram_api::messageMediaEmpty::ID : media_ptr->get_id()) { case telegram_api::messageMediaEmpty::ID: if (message.text.empty()) { LOG(ERROR) << "Receive empty message text and media from " << source; diff --git a/td/telegram/ReplyMarkup.cpp b/td/telegram/ReplyMarkup.cpp index 6e4b51a20..c538b6a8d 100644 --- a/td/telegram/ReplyMarkup.cpp +++ b/td/telegram/ReplyMarkup.cpp @@ -474,8 +474,7 @@ static Result get_keyboard_button(tl_object_ptrtext_); - int32 button_type_id = button->type_ == nullptr ? td_api::keyboardButtonTypeText::ID : button->type_->get_id(); - switch (button_type_id) { + switch (button->type_ == nullptr ? td_api::keyboardButtonTypeText::ID : button->type_->get_id()) { case td_api::keyboardButtonTypeText::ID: current_button.type = KeyboardButton::Type::Text; break; @@ -566,8 +565,7 @@ static Result get_inline_keyboard_button(tl_object_ptrtext_); - int32 button_type_id = button->type_->get_id(); - switch (button_type_id) { + switch (button->type_->get_id()) { case td_api::inlineKeyboardButtonTypeUrl::ID: { auto button_type = move_tl_object_as(button->type_); auto user_id = LinkManager::get_link_user_id(button_type->url_); diff --git a/td/telegram/StoryContent.cpp b/td/telegram/StoryContent.cpp index f95db21f3..f3e3a2a9f 100644 --- a/td/telegram/StoryContent.cpp +++ b/td/telegram/StoryContent.cpp @@ -189,8 +189,7 @@ void add_story_content_dependencies(Dependencies &dependencies, const StoryConte unique_ptr get_story_content(Td *td, tl_object_ptr &&media_ptr, DialogId owner_dialog_id) { CHECK(media_ptr != nullptr); - int32 constructor_id = media_ptr->get_id(); - switch (constructor_id) { + switch (media_ptr->get_id()) { case telegram_api::messageMediaPhoto::ID: { auto media = move_tl_object_as(media_ptr); if (media->photo_ == nullptr || (media->flags_ & telegram_api::messageMediaPhoto::TTL_SECONDS_MASK) != 0 || diff --git a/td/telegram/StoryManager.cpp b/td/telegram/StoryManager.cpp index 8e39a7698..8e2830703 100644 --- a/td/telegram/StoryManager.cpp +++ b/td/telegram/StoryManager.cpp @@ -764,8 +764,7 @@ class GetChatsToSendStoriesQuery final : public Td::ResultHandler { auto chats_ptr = result_ptr.move_as_ok(); LOG(INFO) << "Receive result for GetChatsToSendStoriesQuery: " << to_string(chats_ptr); - int32 constructor_id = chats_ptr->get_id(); - switch (constructor_id) { + switch (chats_ptr->get_id()) { case telegram_api::messages_chats::ID: { auto chats = move_tl_object_as(chats_ptr); td_->story_manager_->on_get_dialogs_to_send_stories(std::move(chats->chats_));