diff --git a/libtransmission/cache.cc b/libtransmission/cache.cc index f25985eb4..e8a680147 100644 --- a/libtransmission/cache.cc +++ b/libtransmission/cache.cc @@ -89,8 +89,14 @@ int Cache::writeContiguous(CIter const begin, CIter const end) const TR_ASSERT(std::size(buf) == buflen); // save it - auto* const tor = torrents_.get(begin->key.first); - auto const loc = tor->blockLoc(begin->key.second); + auto const& [torrent_id, block] = begin->key; + auto* const tor = torrents_.get(torrent_id); + if (tor == nullptr) + { + return EINVAL; + } + + auto const loc = tor->blockLoc(block); if (auto const err = tr_ioWrite(tor, loc, std::size(buf), std::data(buf)); err != 0) {