From 72a041ba4b436d75e4982807921e7764a32bb4fb Mon Sep 17 00:00:00 2001 From: thk123 Date: Mon, 23 Oct 2017 15:42:51 +0100 Subject: [PATCH] Don't crash when found an invalid reference type This is consistent with the original behaviour which would return a nil_typet --- src/java_bytecode/java_types.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/java_bytecode/java_types.cpp b/src/java_bytecode/java_types.cpp index e8fc8e47119..1df84dd3d95 100644 --- a/src/java_bytecode/java_types.cpp +++ b/src/java_bytecode/java_types.cpp @@ -223,13 +223,20 @@ std::string gather_full_class_name(const std::string &src) return class_name; } -reference_typet +/// For parsing a class type reference +/// \param src: The input string +/// Either a signature: "Lpackage/class.innerclass; +/// Or a descriptor: "Lpackage.class$inner; +/// \param class_name_prefix: The name of the class to use to prefix any found +/// generic types +/// \return The reference type if parsed correctly, no value if parsing fails. +optionalt build_class_name(const std::string src, const std::string &class_name_prefix) { PRECONDITION(src[0] == 'L'); // ends on ; if(src[src.size() - 1] != ';') - throw "invalid string for reference type"; + return optionalt(); std::string container_class = gather_full_class_name(src); std::string identifier = "java::" + container_class; @@ -473,7 +480,12 @@ typet java_type_from_string( } case 'L': { - return build_class_name(src, class_name_prefix); + const optionalt &class_type = + build_class_name(src, class_name_prefix); + if(class_type) + return class_type.value(); + else + return nil_typet(); } case '*': case '+':