IOS: Simplify usage of GetVector

By making GetVector return nullptr for invalid indices, we don't have
to check the total number of vectors all the time before calling
GetVector.
This commit is contained in:
Léo Lam 2020-11-29 22:13:32 +01:00
parent 4fea832f49
commit dcbe81b880
No known key found for this signature in database
GPG Key ID: 0DF30F9081000741
2 changed files with 5 additions and 1 deletions

View File

@ -78,7 +78,8 @@ IOCtlVRequest::IOCtlVRequest(const u32 address_) : Request(address_)
const IOCtlVRequest::IOVector* IOCtlVRequest::GetVector(size_t index) const
{
ASSERT(index < (in_vectors.size() + io_vectors.size()));
if (index >= in_vectors.size() + io_vectors.size())
return nullptr;
if (index < in_vectors.size())
return &in_vectors[index];
return &io_vectors[index - in_vectors.size()];

View File

@ -154,7 +154,10 @@ struct IOCtlVRequest final : Request
// merging them into a single std::vector would make using the first out vector more complicated.
std::vector<IOVector> in_vectors;
std::vector<IOVector> io_vectors;
/// Returns the specified vector or nullptr if the index is out of bounds.
const IOVector* GetVector(size_t index) const;
explicit IOCtlVRequest(u32 address);
bool HasNumberOfValidVectors(size_t in_count, size_t io_count) const;
void Dump(std::string_view description, Common::Log::LOG_TYPE type = Common::Log::IOS,