Skip to content

Commit 2710fa9

Browse files
committed
Remove undefined behaviour from pointer-byte-extract5
specifically the C90-style struct hack with non-flexible member.
1 parent d522b10 commit 2710fa9

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

regression/cbmc/Pointer_byte_extract5/main.i

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ typedef union
1111
typedef struct
1212
{
1313
int Count;
14-
Union List[1];
14+
// flexible array member -- note that smt conversion does not yet support
15+
// 0-sized arrays
16+
Union List[0];
1517
} Struct3;
1618
#pragma pack(pop)
1719

1820
int main()
1921
{
20-
Struct3 *p = malloc(sizeof(Struct3) + sizeof(Union));
22+
Struct3 *p = malloc(sizeof(Struct3) + 2 * sizeof(Union));
2123
p->Count = 3;
2224
int po=0;
2325

regression/cbmc/Pointer_byte_extract5/no-simplify.desc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
CORE broken-smt-backend
22
main.i
33
--bounds-check --32 --no-simplify
44
^EXIT=10$
@@ -10,5 +10,6 @@ array\.List dynamic object upper bound in p->List\[2\]: FAILURE
1010
--
1111
Test is built from SV-COMP's memsafety/20051113-1.c_false-valid-memtrack.c.
1212
C90 did not have flexible arrays, and using arrays of size 1 was common
13-
practice: http://c-faq.com/struct/structhack.html. We need to treat those as if
14-
it were a zero-sized array.
13+
practice: http://c-faq.com/struct/structhack.html. But past C90 using
14+
non-flexible members for struct-hack is undefined, hence we changed the test to
15+
use flexible member instead.

regression/cbmc/Pointer_byte_extract5/test.desc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ array\.List dynamic object upper bound in p->List\[2\]: FAILURE
1010
--
1111
Test is built from SV-COMP's memsafety/20051113-1.c_false-valid-memtrack.c.
1212
C90 did not have flexible arrays, and using arrays of size 1 was common
13-
practice: http://c-faq.com/struct/structhack.html. We need to treat those as if
14-
it were a zero-sized array.
13+
practice: http://c-faq.com/struct/structhack.html. But past C90 using
14+
non-flexible members for struct-hack is undefined, hence we changed the test to
15+
use flexible member instead.

0 commit comments

Comments
 (0)