aboutsummaryrefslogtreecommitdiff
path: root/layers/core_validation.cpp
diff options
context:
space:
mode:
authorChris Forbes <chrisforbes@google.com>2016-05-11 11:44:12 +1200
committerChris Forbes <chrisforbes@google.com>2016-05-11 12:46:52 +1200
commit60090b9826873fba84c7b543c2933cabf0f05dc5 (patch)
treeede40992a9d97cb0a3e0b186c0667a38851748b6 /layers/core_validation.cpp
parentf2917409c02b4ea197348b7abfe30f22892c9438 (diff)
downloadusermoji-60090b9826873fba84c7b543c2933cabf0f05dc5.tar.xz
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 <chrisforbes@google.com>
Diffstat (limited to 'layers/core_validation.cpp')
-rw-r--r--layers/core_validation.cpp14
1 files changed, 12 insertions, 2 deletions
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<uint32_t>::const_iterator zero;
std::vector<uint32_t>::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() {}