diff --git a/libtransmission/rpcimpl.cc b/libtransmission/rpcimpl.cc index 876c1d8b1..43bce8310 100644 --- a/libtransmission/rpcimpl.cc +++ b/libtransmission/rpcimpl.cc @@ -903,7 +903,6 @@ void addTorrentInfo(tr_torrent* tor, TrFormat format, tr_variant* entry, tr_quar char const* torrentGet(tr_session* session, tr_variant* args_in, tr_variant* args_out, tr_rpc_idle_data* /*idle_data*/) { auto const torrents = getTorrents(session, args_in); - tr_variant* const list = tr_variantDictAddList(args_out, TR_KEY_torrents, std::size(torrents) + 1); auto sv = std::string_view{}; auto const format = tr_variantDictFindStrView(args_in, TR_KEY_format, &sv) && sv == "table"sv ? TrFormat::Table : @@ -945,6 +944,8 @@ char const* torrentGet(tr_session* session, tr_variant* args_in, tr_variant* arg } } + auto* const list = tr_variantDictAddList(args_out, TR_KEY_torrents, std::size(torrents) + 1U); + if (format == TrFormat::Table) { /* first entry is an array of property names */ diff --git a/libtransmission/variant.h b/libtransmission/variant.h index 8031bec39..6953594b6 100644 --- a/libtransmission/variant.h +++ b/libtransmission/variant.h @@ -9,6 +9,7 @@ #include // size_t #include // int64_t #include +#include #include #include #include // std::is_same_v @@ -102,9 +103,9 @@ public: return std::empty(vec_); } - void reserve(size_t new_cap) + void reserve(size_t const new_cap) { - vec_.reserve(new_cap); + vec_.reserve(std::max(new_cap, size_t{ 16U })); } auto erase(tr_quark const key)