From dcbe81b88076891655b9e7cc150aa5b6c8219f80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sun, 29 Nov 2020 22:13:32 +0100 Subject: [PATCH] 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. --- Source/Core/Core/IOS/Device.cpp | 3 ++- Source/Core/Core/IOS/Device.h | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Source/Core/Core/IOS/Device.cpp b/Source/Core/Core/IOS/Device.cpp index b3324503f0..9d04dca6ba 100644 --- a/Source/Core/Core/IOS/Device.cpp +++ b/Source/Core/Core/IOS/Device.cpp @@ -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()]; diff --git a/Source/Core/Core/IOS/Device.h b/Source/Core/Core/IOS/Device.h index bffe1cdc1c..b3944eb16e 100644 --- a/Source/Core/Core/IOS/Device.h +++ b/Source/Core/Core/IOS/Device.h @@ -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 in_vectors; std::vector 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,