Fix parser assert failure for a bad OpSwitch
Emit a diagnostic if the OpSwitch selector refers to an ID that
is valid but has no type.
Discovered by afl-fuzz.
diff --git a/source/binary.cpp b/source/binary.cpp
index 533fe7f..99cf30f 100755
--- a/source/binary.cpp
+++ b/source/binary.cpp
@@ -555,8 +555,9 @@
// The literal operands have the same type as the value
// referenced by the selector Id.
const uint32_t selector_id = peekAt(inst_offset + 1);
- auto type_id_iter = _.id_to_type_id.find(selector_id);
- if (type_id_iter == _.id_to_type_id.end()) {
+ const auto type_id_iter = _.id_to_type_id.find(selector_id);
+ if (type_id_iter == _.id_to_type_id.end() ||
+ type_id_iter->second == 0) {
return diagnostic() << "Invalid OpSwitch: selector id " << selector_id
<< " has no type";
}