From 9e07b6f4c570a84b8ff5ef97ee41dfbce0b30726 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 26 Aug 2022 14:46:46 -0500 Subject: [PATCH] fixup! refactor: modernize cache.cc (#3108) (#3715) --- libtransmission/cache.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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) {