From a59e6b8ffe11e3600ce163b3755c453ddceaf565 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 1 Mar 2022 21:39:24 +0300 Subject: [PATCH] Add static_assert that flag in STORE_FLAG/PARSE_FLAG is bool. --- td/telegram/MessagesManager.cpp | 4 ++-- tdutils/td/utils/tl_helpers.h | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index c0befc67d..b339665cd 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -5468,7 +5468,7 @@ void MessagesManager::Dialog::store(StorerT &storer) const { STORE_FLAG(need_drop_default_send_message_as_dialog_id); STORE_FLAG(has_available_reactions); STORE_FLAG(is_available_reactions_inited); - STORE_FLAG(available_reactions_generation); + STORE_FLAG(has_available_reactions_generation); END_STORE_FLAGS(); } @@ -23700,7 +23700,7 @@ unique_ptr MessagesManager::parse_message(Dialog *d, M LOG(ERROR) << "Fix available_reactions_generation in " << dialog_id << " from " << d->available_reactions_generation << " to " << m->available_reactions_generation; hide_dialog_message_reactions(d); - set_dialog_available_reactions_generation(d, m->available_reactions_generation); + set_dialog_available_reactions_generation(d, m->available_reactions_generation + 1); on_dialog_updated(dialog_id, "parse_message"); break; case DialogType::User: diff --git a/tdutils/td/utils/tl_helpers.h b/tdutils/td/utils/tl_helpers.h index 4cb430342..743e6a723 100644 --- a/tdutils/td/utils/tl_helpers.h +++ b/tdutils/td/utils/tl_helpers.h @@ -26,8 +26,9 @@ ::td::uint32 flags_store = 0; \ ::td::uint32 bit_offset_store = 0 -#define STORE_FLAG(flag) \ - flags_store |= (flag) << bit_offset_store; \ +#define STORE_FLAG(flag) \ + static_assert(std::is_same::value, "flag must be bool"); \ + flags_store |= (flag) << bit_offset_store; \ bit_offset_store++ #define END_STORE_FLAGS() \ @@ -42,8 +43,9 @@ ::td::uint32 bit_offset_parse = 0; \ ::td::parse(flags_parse, parser) -#define PARSE_FLAG(flag) \ - flag = ((flags_parse >> bit_offset_parse) & 1) != 0; \ +#define PARSE_FLAG(flag) \ + static_assert(std::is_same::value, "flag must be bool"); \ + flag = ((flags_parse >> bit_offset_parse) & 1) != 0; \ bit_offset_parse++ #define END_PARSE_FLAGS() \