diff --git a/td/telegram/OptionManager.cpp b/td/telegram/OptionManager.cpp index bcefbfc48..0bd706086 100644 --- a/td/telegram/OptionManager.cpp +++ b/td/telegram/OptionManager.cpp @@ -35,6 +35,7 @@ #include "td/utils/Status.h" #include +#include #include namespace td { @@ -418,14 +419,14 @@ void OptionManager::set_option(const string &name, td_api::object_ptrshared_config().set_option_empty(option_name); } else { + if (value_constructor_id != td_api::optionValueInteger::ID) { + promise.set_error(Status::Error(400, PSLICE() << "Option \"" << name << "\" must have integer value")); + return false; + } + int64 int_value = static_cast(value.get())->value_; if (int_value < min_value || int_value > max_value) { promise.set_error(Status::Error(400, PSLICE() << "Option's \"" << name << "\" value " << int_value @@ -443,14 +444,14 @@ void OptionManager::set_option(const string &name, td_api::object_ptrshared_config().set_option_empty(name); } else { + if (value_constructor_id != td_api::optionValueBoolean::ID) { + promise.set_error(Status::Error(400, PSLICE() << "Option \"" << name << "\" must have boolean value")); + return false; + } + bool bool_value = static_cast(value.get())->value_; G()->shared_config().set_option_boolean(name, bool_value); } @@ -458,17 +459,18 @@ void OptionManager::set_option(const string &name, td_api::object_ptr check_value) { if (name != option_name) { return false; } - if (value_constructor_id != td_api::optionValueString::ID && value_constructor_id != td_api::optionValueEmpty::ID) { - promise.set_error(Status::Error(400, PSLICE() << "Option \"" << name << "\" must have string value")); - return false; - } if (value_constructor_id == td_api::optionValueEmpty::ID) { G()->shared_config().set_option_empty(name); } else { + if (value_constructor_id != td_api::optionValueString::ID) { + promise.set_error(Status::Error(400, PSLICE() << "Option \"" << name << "\" must have string value")); + return false; + } + const string &str_value = static_cast(value.get())->value_; if (str_value.empty()) { G()->shared_config().set_option_empty(name);