Skip to content

Commit bc07b78

Browse files
committed
Check 2nd arg to points_to_valid_memory is size_t
This commit ensures that the second argument to the __CPROVER_points_to_valid_memory directive can be coerced to a size_t, and adds a test to check for the failing case.
1 parent ae4b259 commit bc07b78

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
int main()
2+
{
3+
int *r;
4+
__CPROVER_points_to_valid_memory(r, "huh?");
5+
}
5.81 KB
Binary file not shown.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
--apply-code-contracts
4+
^EXIT=1$
5+
^SIGNAL=0$
6+
^main.c:\d+:\d+: error: size argument to points_to_valid_memory must be coercible to size_t$
7+
^CONVERSION ERROR$
8+
--
9+
--

src/ansi-c/c_typecheck_expr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2131,10 +2131,10 @@ exprt c_typecheck_baset::do_special_functions(
21312131
if(expr.arguments().size() == 2)
21322132
{
21332133
if(
2134-
expr.arguments()[1].type() != ID_unsignedbv &&
2135-
expr.arguments()[1].type() != ID_signedbv)
2134+
expr.arguments()[1].type().id() != ID_unsignedbv &&
2135+
expr.arguments()[1].type().id() != ID_signedbv)
21362136
{
2137-
err_location(f_op);
2137+
error().source_location = f_op.source_location();
21382138
error() << "size argument to points_to_valid_memory"
21392139
<< " must be coercible to size_t" << eom;
21402140
throw 0;

0 commit comments

Comments
 (0)