Skip to content

Commit

Permalink
Don't crash when found an invalid reference type
Browse files Browse the repository at this point in the history
This is consistent with the original behaviour which would return a
nil_typet
  • Loading branch information
thk123 committed Oct 26, 2017
1 parent ed545cb commit 72a041b
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/java_bytecode/java_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<TT;>.innerclass<Ljava/lang/Foo;>;
/// 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<reference_typet>
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<reference_typet>();

std::string container_class = gather_full_class_name(src);
std::string identifier = "java::" + container_class;
Expand Down Expand Up @@ -473,7 +480,12 @@ typet java_type_from_string(
}
case 'L':
{
return build_class_name(src, class_name_prefix);
const optionalt<reference_typet> &class_type =
build_class_name(src, class_name_prefix);
if(class_type)
return class_type.value();
else
return nil_typet();
}
case '*':
case '+':
Expand Down

0 comments on commit 72a041b

Please sign in to comment.