Skip to content

Commit d2713b2

Browse files
author
Daniel Kroening
committed
check for null being thrown in Java
1 parent e3f0112 commit d2713b2

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

regression/cbmc-java/NullPointer3/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
CORE
22
NullPointer3.class
33
--pointer-check
44
^EXIT=10$

src/analyses/goto_check.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,6 @@ void goto_checkt::pointer_validity_check(
919919
if(flags.is_unknown() || flags.is_null())
920920
{
921921
notequal_exprt not_eq_null(pointer, gen_zero(pointer.type()));
922-
//exprt not_eq_null=not_exprt(null_pointer(pointer));
923922

924923
add_guarded_claim(
925924
not_eq_null,
@@ -1537,6 +1536,24 @@ void goto_checkt::goto_check(goto_functiont &goto_function)
15371536
}
15381537
else if(i.is_throw())
15391538
{
1539+
if(i.code.get_statement()==ID_expression &&
1540+
i.code.operands().size()==1 &&
1541+
i.code.op0().operands().size()==1)
1542+
{
1543+
// must not throw NULL
1544+
1545+
exprt pointer=i.code.op0().op0();
1546+
notequal_exprt not_eq_null(pointer, gen_zero(pointer.type()));
1547+
1548+
add_guarded_claim(
1549+
not_eq_null,
1550+
"throwing null",
1551+
"pointer dereference",
1552+
i.source_location,
1553+
pointer,
1554+
guardt());
1555+
}
1556+
15401557
// this has no successor
15411558
assertions.clear();
15421559
}

0 commit comments

Comments
 (0)