From 60090b9826873fba84c7b543c2933cabf0f05dc5 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Wed, 11 May 2016 11:44:12 +1200 Subject: layers: add some asserts to spirv_inst_iter These allow us to more easily catch in debug: - Bogus zero-length instructions - Reads off the end of the instruction Signed-off-by: Chris Forbes --- layers/core_validation.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'layers/core_validation.cpp') diff --git a/layers/core_validation.cpp b/layers/core_validation.cpp index 78ede930..bba96b7a 100644 --- a/layers/core_validation.cpp +++ b/layers/core_validation.cpp @@ -171,9 +171,19 @@ struct spirv_inst_iter { std::vector::const_iterator zero; std::vector::const_iterator it; - uint32_t len() { return *it >> 16; } + uint32_t len() { + auto result = *it >> 16; + assert(result > 0); + return result; + } + uint32_t opcode() { return *it & 0x0ffffu; } - uint32_t const &word(unsigned n) { return it[n]; } + + uint32_t const &word(unsigned n) { + assert(n < len()); + return it[n]; + } + uint32_t offset() { return (uint32_t)(it - zero); } spirv_inst_iter() {} -- cgit v1.2.3