Skip to content

Commit f78b8f8

Browse files
committed
Two new failing tests demonstrating updates outside member bounds
These examples write to a member different from the access path being used, yet within the object bounds.
1 parent 7774e1c commit f78b8f8

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

regression/cbmc/member_bounds1/main.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <assert.h>
2+
3+
#pragma pack(push, 1)
4+
struct S
5+
{
6+
int a[2];
7+
int x;
8+
};
9+
#pragma pack(pop)
10+
11+
#ifdef _MSC_VER
12+
# define _Static_assert(x, m) static_assert(x, m)
13+
#endif
14+
15+
int main()
16+
{
17+
int A[3];
18+
_Static_assert(sizeof(A) == sizeof(struct S), "");
19+
struct S *s = A;
20+
s->a[2] = 42;
21+
assert(*((int *)s + 2) == 42);
22+
assert(s->x == 42);
23+
assert(A[2] == 42);
24+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
KNOWNBUG
2+
main.c
3+
--no-simplify
4+
^VERIFICATION SUCCESSFUL$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring
9+
--
10+
This test passes when using the simplifier, but results in "WITH" expressions
11+
that update elements outside their bounds without the simplifier.

regression/cbmc/member_bounds2/main.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <assert.h>
2+
3+
#pragma pack(push, 1)
4+
struct SU
5+
{
6+
union {
7+
int a[2];
8+
} u;
9+
int x;
10+
};
11+
#pragma pack(pop)
12+
13+
int main()
14+
{
15+
struct SU su;
16+
su.u.a[2] = 42;
17+
assert(*((int *)&su + 2) == 42);
18+
assert(su.x == 42);
19+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
KNOWNBUG
2+
main.c
3+
4+
^VERIFICATION SUCCESSFUL$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring
9+
--
10+
Field sensitivity makes it (currently) impossible to update bytes outside the
11+
particular field.

0 commit comments

Comments
 (0)