Skip to content

Commit f585e60

Browse files
committed
Stop asserting positive array size
when generating non-deterministic arrays. Zero-sized arrays are (unfortunately) legal C construct (as for example the regression test shows).
1 parent c71d73c commit f585e60

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

Diff for: regression/cbmc/Struct_Hack_Initialization/main.c

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <assert.h>
2+
3+
typedef struct stritem
4+
{
5+
unsigned nkey;
6+
unsigned cas[];
7+
} item;
8+
9+
int foo(item *it)
10+
{
11+
assert(it->cas[0] == 0);
12+
return 0;
13+
}

Diff for: regression/cbmc/Struct_Hack_Initialization/test.desc

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CORE
2+
main.c
3+
--function foo --bounds-check --pointer-check
4+
^\[foo.assertion.1\] line \d+ assertion it->cas\[0\] == 0: FAILURE$
5+
^\[foo.array_bounds.3\] line \d+ array.cas upper bound in it->cas\[\(.*\)0\]: FAILURE$
6+
^\[foo.array_bounds.2\] line \d+ array.cas dynamic object upper bound in it->cas\[\(.*\)0\]: FAILURE$
7+
^\[foo.pointer_dereference.2\] line \d+ dereference failure: pointer invalid in it->cas: SUCCESS$
8+
^\[foo.pointer_dereference.6\] line \d+ dereference failure: pointer outside object bounds in it->cas: FAILURE$
9+
^EXIT=10$
10+
^SIGNAL=0$
11+
^VERIFICATION FAILED$
12+
--
13+
^warning: ignoring

Diff for: src/ansi-c/c_nondet_symbol_factory.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ void symbol_factoryt::gen_nondet_array_init(
163163
const auto &size = array_type.size();
164164
PRECONDITION(size.id() == ID_constant);
165165
auto const array_size = numeric_cast_v<size_t>(to_constant_expr(size));
166-
DATA_INVARIANT(array_size > 0, "Arrays should have positive size");
167166
for(size_t index = 0; index < array_size; ++index)
168167
{
169168
gen_nondet_init(

0 commit comments

Comments
 (0)