diff --git a/libtransmission/rpcimpl.cc b/libtransmission/rpcimpl.cc index 091008ef7..e2f03d4f4 100644 --- a/libtransmission/rpcimpl.cc +++ b/libtransmission/rpcimpl.cc @@ -136,7 +136,7 @@ auto getTorrents(tr_session* session, tr_variant* args) std::begin(by_id), std::end(by_id), std::back_inserter(torrents), - [&cutoff](auto const* tor) { return tor->anyDate >= cutoff; }); + [&cutoff](auto const* tor) { return tor != nullptr && tor->anyDate >= cutoff; }); } else { @@ -150,7 +150,12 @@ auto getTorrents(tr_session* session, tr_variant* args) else // all of them { auto const& by_id = session->torrents().sorted_by_id(); - torrents = std::vector{ std::begin(by_id), std::end(by_id) }; + torrents.reserve(std::size(by_id)); + std::copy_if( + std::begin(by_id), + std::end(by_id), + std::back_inserter(torrents), + [](auto const* tor) { return tor != nullptr; }); } return torrents;