diff --git a/td/telegram/MessagesDb.cpp b/td/telegram/MessagesDb.cpp index 905019e96..125391b79 100644 --- a/td/telegram/MessagesDb.cpp +++ b/td/telegram/MessagesDb.cpp @@ -847,16 +847,14 @@ class MessagesDbImpl : public MessagesDbSyncInterface { left_cnt++; } - TRY_RESULT(left_tmp, get_messages_inner(stmt.desc_stmt_, dialog_id, left_message_id, left_cnt)); - left = std::move(left_tmp); + TRY_RESULT_ASSIGN(left, get_messages_inner(stmt.desc_stmt_, dialog_id, left_message_id, left_cnt)); if (right_cnt == 1 && !left.empty() && false /*get_message_id(left[0].as_slice()) == message_id*/) { right_cnt = 0; } } if (right_cnt != 0) { - TRY_RESULT(right_tmp, get_messages_inner(stmt.asc_stmt_, dialog_id, right_message_id, right_cnt)); - right = std::move(right_tmp); + TRY_RESULT_ASSIGN(right, get_messages_inner(stmt.asc_stmt_, dialog_id, right_message_id, right_cnt)); std::reverse(right.begin(), right.end()); } if (left.empty()) { diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp index b480e2246..f8842f0df 100644 --- a/td/telegram/NotificationManager.cpp +++ b/td/telegram/NotificationManager.cpp @@ -3210,8 +3210,7 @@ Status NotificationManager::process_push_notification_payload(string payload, bo if (mtpeer.type() != JsonValue::Type::Null) { TRY_RESULT(ah, get_json_object_string_field(mtpeer.get_object(), "ah")); if (!ah.empty()) { - TRY_RESULT(sender_access_hash_safe, to_integer_safe(ah)); - sender_access_hash = sender_access_hash_safe; + TRY_RESULT_ASSIGN(sender_access_hash, to_integer_safe(ah)); } TRY_RESULT(ph, get_json_object_field(mtpeer.get_object(), "ph", JsonValue::Type::Object)); if (ph.type() != JsonValue::Type::Null) { diff --git a/td/telegram/ReplyMarkup.cpp b/td/telegram/ReplyMarkup.cpp index 95c6576b6..052832e8c 100644 --- a/td/telegram/ReplyMarkup.cpp +++ b/td/telegram/ReplyMarkup.cpp @@ -380,8 +380,8 @@ static Result get_inline_keyboard_button(tl_object_ptr(button->type_.get())->url_)); - current_button.data = std::move(url); + TRY_RESULT_ASSIGN(current_button.data, + check_url(static_cast(button->type_.get())->url_)); if (!clean_input_string(current_button.data)) { return Status::Error(400, "Inline keyboard button url must be encoded in UTF-8"); } @@ -420,8 +420,7 @@ static Result get_inline_keyboard_button(tl_object_ptr(button->type_); - TRY_RESULT(url, check_url(login_url->url_)); - current_button.data = std::move(url); + TRY_RESULT_ASSIGN(current_button.data, check_url(login_url->url_)); current_button.forward_text = std::move(login_url->forward_text_); if (!clean_input_string(current_button.data)) { return Status::Error(400, "Inline keyboard button login url must be encoded in UTF-8"); diff --git a/td/telegram/SecureValue.cpp b/td/telegram/SecureValue.cpp index 528b5286d..d1ca22084 100644 --- a/td/telegram/SecureValue.cpp +++ b/td/telegram/SecureValue.cpp @@ -892,19 +892,15 @@ static Result get_identity_document(SecureValueType type, FileManag } } - TRY_RESULT(front_side, get_secure_file(file_manager, std::move(identity_document->front_side_))); - res.front_side = std::move(front_side); + TRY_RESULT_ASSIGN(res.front_side, get_secure_file(file_manager, std::move(identity_document->front_side_))); if (identity_document->reverse_side_ != nullptr) { - TRY_RESULT(reverse_side, get_secure_file(file_manager, std::move(identity_document->reverse_side_))); - res.reverse_side = std::move(reverse_side); + TRY_RESULT_ASSIGN(res.reverse_side, get_secure_file(file_manager, std::move(identity_document->reverse_side_))); } if (identity_document->selfie_ != nullptr) { - TRY_RESULT(selfie, get_secure_file(file_manager, std::move(identity_document->selfie_))); - res.selfie = std::move(selfie); + TRY_RESULT_ASSIGN(res.selfie, get_secure_file(file_manager, std::move(identity_document->selfie_))); } if (!identity_document->translation_.empty()) { - TRY_RESULT(translations, get_secure_files(file_manager, std::move(identity_document->translation_))); - res.translations = std::move(translations); + TRY_RESULT_ASSIGN(res.translations, get_secure_files(file_manager, std::move(identity_document->translation_))); } return res; } @@ -962,11 +958,9 @@ static Result get_personal_document( if (personal_document->files_.empty()) { return Status::Error(400, "Document's files are required"); } - TRY_RESULT(files, get_secure_files(file_manager, std::move(personal_document->files_))); - res.files = std::move(files); + TRY_RESULT_ASSIGN(res.files, get_secure_files(file_manager, std::move(personal_document->files_))); if (!personal_document->translation_.empty()) { - TRY_RESULT(translations, get_secure_files(file_manager, std::move(personal_document->translation_))); - res.translations = std::move(translations); + TRY_RESULT_ASSIGN(res.translations, get_secure_files(file_manager, std::move(personal_document->translation_))); } return res; } @@ -1002,8 +996,7 @@ Result get_secure_value(FileManager *file_manager, case td_api::inputPassportElementPersonalDetails::ID: { auto input = td_api::move_object_as(input_passport_element); res.type = SecureValueType::PersonalDetails; - TRY_RESULT(personal_details, get_personal_details(std::move(input->personal_details_))); - res.data = std::move(personal_details); + TRY_RESULT_ASSIGN(res.data, get_personal_details(std::move(input->personal_details_))); break; } case td_api::inputPassportElementPassport::ID: { @@ -1455,7 +1448,7 @@ static auto credentials_as_jsonable(const std::vector &c })); } })); - o(rename_payload_to_nonce ? "nonce" : "payload", nonce); + o(rename_payload_to_nonce ? Slice("nonce") : Slice("payload"), nonce); }); } diff --git a/td/telegram/files/FileDownloader.cpp b/td/telegram/files/FileDownloader.cpp index f77f7af76..094f2d0ce 100644 --- a/td/telegram/files/FileDownloader.cpp +++ b/td/telegram/files/FileDownloader.cpp @@ -135,8 +135,7 @@ Status FileDownloader::on_ok(int64 size) { if (only_check_) { path = path_; } else { - TRY_RESULT(perm_path, create_from_temp(path_, dir, name_)); - path = std::move(perm_path); + TRY_RESULT_ASSIGN(path, create_from_temp(path_, dir, name_)); } callback_->on_ok(FullLocalFileLocation(remote_.file_type_, std::move(path), 0), size, !only_check_); return Status::OK(); @@ -492,11 +491,9 @@ void FileDownloader::try_release_fd() { Status FileDownloader::acquire_fd() { if (fd_.empty()) { if (path_.empty()) { - TRY_RESULT(file_path, open_temp_file(remote_.file_type_)); - std::tie(fd_, path_) = std::move(file_path); + TRY_RESULT_ASSIGN(std::tie(fd_, path_), open_temp_file(remote_.file_type_)); } else { - TRY_RESULT(fd, FileFd::open(path_, (only_check_ ? 0 : FileFd::Write) | FileFd::Read)); - fd_ = std::move(fd); + TRY_RESULT_ASSIGN(fd_, FileFd::open(path_, (only_check_ ? 0 : FileFd::Write) | FileFd::Read)); } } return Status::OK(); diff --git a/td/telegram/files/FileUploader.cpp b/td/telegram/files/FileUploader.cpp index cd7519ed4..b8c3be64b 100644 --- a/td/telegram/files/FileUploader.cpp +++ b/td/telegram/files/FileUploader.cpp @@ -167,8 +167,7 @@ Result FileUploader::on_update_local_location(const Loca } if (local_is_ready) { CHECK(!fd_.empty()); - TRY_RESULT(local_file_size, fd_.get_size()); - local_size = local_file_size; + TRY_RESULT_ASSIGN(local_size, fd_.get_size()); LOG(INFO) << "Set file local_size to " << local_size; if (local_size == 0) { return Status::Error("Can't upload empty file"); @@ -338,8 +337,7 @@ void FileUploader::try_release_fd() { Status FileUploader::acquire_fd() { if (fd_.empty()) { - TRY_RESULT(fd, FileFd::open(fd_path_, FileFd::Read)); - fd_ = std::move(fd); + TRY_RESULT_ASSIGN(fd_, FileFd::open(fd_path_, FileFd::Read)); } return Status::OK(); } diff --git a/td/telegram/net/ConnectionCreator.cpp b/td/telegram/net/ConnectionCreator.cpp index f228e3fe1..040a663ea 100644 --- a/td/telegram/net/ConnectionCreator.cpp +++ b/td/telegram/net/ConnectionCreator.cpp @@ -685,8 +685,7 @@ Result ConnectionCreator::find_connection(const Proxy &proxy, const IP TRY_RESULT(info, dc_options_set_.find_connection( dc_id, allow_media_only, proxy.use_proxy() && proxy.use_socks5_proxy(), prefer_ipv6, only_http)); extra.stat = info.stat; - TRY_RESULT(transport_type, get_transport_type(proxy, info)); - extra.transport_type = std::move(transport_type); + TRY_RESULT_ASSIGN(extra.transport_type, get_transport_type(proxy, info)); extra.debug_str = PSTRING() << " to " << (info.option->is_media_only() ? "MEDIA " : "") << dc_id << (info.use_http ? " over HTTP" : ""); diff --git a/td/tl/tl_json.h b/td/tl/tl_json.h index 1ff559a32..7c5751417 100644 --- a/td/tl/tl_json.h +++ b/td/tl/tl_json.h @@ -81,8 +81,7 @@ inline Status from_json(int32 &to, JsonValue &from) { return Status::Error(PSLICE() << "Expected Number, got " << from.type()); } Slice number = from.type() == JsonValue::Type::String ? from.get_string() : from.get_number(); - TRY_RESULT(res, to_integer_safe(number)); - to = res; + TRY_RESULT_ASSIGN(to, to_integer_safe(number)); return Status::OK(); } @@ -105,8 +104,7 @@ inline Status from_json(int64 &to, JsonValue &from) { return Status::Error(PSLICE() << "Expected String or Number, got " << from.type()); } Slice number = from.type() == JsonValue::Type::String ? from.get_string() : from.get_number(); - TRY_RESULT(res, to_integer_safe(number)); - to = res; + TRY_RESULT_ASSIGN(to, to_integer_safe(number)); return Status::OK(); } @@ -130,8 +128,7 @@ inline Status from_json_bytes(string &to, JsonValue &from) { if (from.type() != JsonValue::Type::String) { return Status::Error(PSLICE() << "Expected String, got " << from.type()); } - TRY_RESULT(decoded, base64_decode(from.get_string())); - to = std::move(decoded); + TRY_RESULT_ASSIGN(to, base64_decode(from.get_string())); return Status::OK(); } @@ -180,8 +177,7 @@ std::enable_if_t::value, Status> from_json(tl_object_p if (constructor_value.type() == JsonValue::Type::Number) { constructor = to_integer(constructor_value.get_number()); } else if (constructor_value.type() == JsonValue::Type::String) { - TRY_RESULT(t_constructor, tl_constructor_from_string(to.get(), constructor_value.get_string().str())); - constructor = t_constructor; + TRY_RESULT_ASSIGN(constructor, tl_constructor_from_string(to.get(), constructor_value.get_string().str())); } else { return Status::Error(PSLICE() << "Expected String or Integer, got " << constructor_value.type()); } diff --git a/tdnet/td/net/Wget.cpp b/tdnet/td/net/Wget.cpp index bd76d04f6..d8ea8de23 100644 --- a/tdnet/td/net/Wget.cpp +++ b/tdnet/td/net/Wget.cpp @@ -38,8 +38,7 @@ Wget::Wget(Promise> promise, string url, std::vector Result read_file_impl(CSlice path, int64 size, int64 offset) { TRY_RESULT(from_file, FileFd::open(path, FileFd::Read)); if (size == -1) { - TRY_RESULT(file_size, from_file.get_size()); - size = file_size; + TRY_RESULT_ASSIGN(size, from_file.get_size()); } if (size < 0) { return Status::Error("Failed to read file: invalid size"); diff --git a/tdutils/td/utils/port/IPAddress.cpp b/tdutils/td/utils/port/IPAddress.cpp index 3cc8aad77..b2727aa96 100644 --- a/tdutils/td/utils/port/IPAddress.cpp +++ b/tdutils/td/utils/port/IPAddress.cpp @@ -386,7 +386,7 @@ Status IPAddress::init_host_port(CSlice host, CSlice port, bool prefer_ipv6) { } #endif TRY_RESULT(ascii_host, idn_to_ascii(host)); - host = ascii_host; + host = ascii_host; // assign string to CSlice // some getaddrinfo implementations use inet_pton instead of inet_aton and support only decimal-dotted IPv4 form, // and so doesn't recognize 0x12.0x34.0x56.0x78, or 0x12345678, or 0x7f.001 as valid IPv4 addresses diff --git a/tdutils/td/utils/port/path.cpp b/tdutils/td/utils/port/path.cpp index 8dcbc54f8..6ed127668 100644 --- a/tdutils/td/utils/port/path.cpp +++ b/tdutils/td/utils/port/path.cpp @@ -56,8 +56,7 @@ Status set_temporary_dir(CSlice dir) { input_dir += TD_DIR_SLASH; } TRY_STATUS(mkpath(input_dir, 0750)); - TRY_RESULT(real_dir, realpath(input_dir)); - temporary_dir = std::move(real_dir); + TRY_RESULT_ASSIGN(temporary_dir, realpath(input_dir)); return Status::OK(); } @@ -419,8 +418,7 @@ Result realpath(CSlice slice, bool ignore_access_denied) { return OS_ERROR(PSLICE() << "GetFullPathNameW failed for \"" << slice << '"'); } } else { - TRY_RESULT(t_res, from_wstring(buf)); - res = std::move(t_res); + TRY_RESULT_ASSIGN(res, from_wstring(buf)); } if (res.empty()) { return Status::Error("Empty path");