fix: crash after nullptr dereference in rpcimpl (#6177) (#6348)

Co-authored-by: Dzmitry Neviadomski <nevack.d@gmail.com>
This commit is contained in:
Charles Kerr
2023-12-06 15:24:13 -06:00
committed by GitHub
parent 782114798b
commit d1333e6aa1

View File

@@ -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<tr_torrent*>{ 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;