Skip to content

Commit 0149e41

Browse files
author
Daniel Kroening
committed
object_size can now do objects with variable size
1 parent e2315f7 commit 0149e41

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
struct S
2+
{
3+
__CPROVER_size_t size;
4+
char *p;
5+
};
6+
7+
void func(struct S *s)
8+
{
9+
char *p = s->p;
10+
__CPROVER_size_t size = __CPROVER_OBJECT_SIZE(p);
11+
__CPROVER_assert(size == s->size, "size ok");
12+
p[80] = 123; // should be safe
13+
}
14+
15+
int main()
16+
{
17+
__CPROVER_size_t buffer_size;
18+
__CPROVER_assume(buffer_size >= 100);
19+
char buffer[buffer_size];
20+
struct S s;
21+
s.size = buffer_size;
22+
s.p = buffer;
23+
func(&s);
24+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
stack_object.c
3+
--pointer-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

src/solvers/flattening/bv_pointers.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ void bv_pointerst::do_postponed(
786786
{
787787
const exprt &expr=*it;
788788

789-
mp_integer object_size;
789+
exprt object_size;
790790

791791
if(expr.id()==ID_symbol)
792792
{
@@ -798,8 +798,8 @@ void bv_pointerst::do_postponed(
798798
if(size_expr.is_nil())
799799
continue;
800800

801-
if(to_integer(size_expr, object_size))
802-
continue;
801+
object_size =
802+
typecast_exprt::conditional_cast(size_expr, postponed.expr.type());
803803
}
804804
else
805805
continue;
@@ -813,12 +813,13 @@ void bv_pointerst::do_postponed(
813813
bvt saved_bv=postponed.op;
814814
saved_bv.erase(saved_bv.begin(), saved_bv.begin()+offset_bits);
815815

816+
bvt size_bv = convert_bv(object_size);
817+
816818
POSTCONDITION(bv.size()==saved_bv.size());
817819
PRECONDITION(postponed.bv.size()>=1);
820+
PRECONDITION(size_bv.size() == postponed.bv.size());
818821

819822
literalt l1=bv_utils.equal(bv, saved_bv);
820-
821-
bvt size_bv=bv_utils.build_constant(object_size, postponed.bv.size());
822823
literalt l2=bv_utils.equal(postponed.bv, size_bv);
823824

824825
prop.l_set_to(prop.limplies(l1, l2), true);

0 commit comments

Comments
 (0)