Skip to content

Commit 72a041b

Browse files
author
thk123
committed
Don't crash when found an invalid reference type
This is consistent with the original behaviour which would return a nil_typet
1 parent ed545cb commit 72a041b

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/java_bytecode/java_types.cpp

+15-3
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,20 @@ std::string gather_full_class_name(const std::string &src)
223223
return class_name;
224224
}
225225

226-
reference_typet
226+
/// For parsing a class type reference
227+
/// \param src: The input string
228+
/// Either a signature: "Lpackage/class<TT;>.innerclass<Ljava/lang/Foo;>;
229+
/// Or a descriptor: "Lpackage.class$inner;
230+
/// \param class_name_prefix: The name of the class to use to prefix any found
231+
/// generic types
232+
/// \return The reference type if parsed correctly, no value if parsing fails.
233+
optionalt<reference_typet>
227234
build_class_name(const std::string src, const std::string &class_name_prefix)
228235
{
229236
PRECONDITION(src[0] == 'L');
230237
// ends on ;
231238
if(src[src.size() - 1] != ';')
232-
throw "invalid string for reference type";
239+
return optionalt<reference_typet>();
233240

234241
std::string container_class = gather_full_class_name(src);
235242
std::string identifier = "java::" + container_class;
@@ -473,7 +480,12 @@ typet java_type_from_string(
473480
}
474481
case 'L':
475482
{
476-
return build_class_name(src, class_name_prefix);
483+
const optionalt<reference_typet> &class_type =
484+
build_class_name(src, class_name_prefix);
485+
if(class_type)
486+
return class_type.value();
487+
else
488+
return nil_typet();
477489
}
478490
case '*':
479491
case '+':

0 commit comments

Comments
 (0)