Skip to content

Commit b32032f

Browse files
committed
Add boundary size tests
for the malloc-max-check option.
1 parent 640cdcc commit b32032f

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <assert.h>
2+
#include <stdint.h>
3+
#include <stdlib.h>
4+
5+
int main()
6+
{
7+
size_t pointer_width = sizeof(void *) * 8;
8+
size_t object_bits = 8; // by default
9+
size_t cbmc_max_alloc_size = (size_t)1 << (pointer_width - object_bits);
10+
int *p2 = malloc(cbmc_max_alloc_size - 1); // try to allocate exactly the max
11+
12+
return 0;
13+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
--malloc-max-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^\[malloc.max_allocation_check.\d+\] line \d+ malloc_size < 2 \^ \(pointer_width - object_size\) in ALLOCATE\(malloc_size, 0 != 0\): SUCCESS$
7+
^VERIFICATION SUCCESSFUL$
8+
--
9+
^warning: ignoring
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <assert.h>
2+
#include <stdint.h>
3+
#include <stdlib.h>
4+
5+
int main()
6+
{
7+
size_t pointer_width = sizeof(void *) * 8;
8+
size_t object_bits = 8; // by default
9+
size_t cbmc_max_alloc_size = (size_t)1 << (pointer_width - object_bits);
10+
// try to allocate the smallest violating amount
11+
int *p3 = malloc(cbmc_max_alloc_size);
12+
13+
return 0;
14+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
--malloc-max-check
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^\[malloc.max_allocation_check.\d+\] line \d+ malloc_size < 2 \^ \(pointer_width - object_size\) in ALLOCATE\(malloc_size, 0 != 0\): FAILURE$
7+
^VERIFICATION FAILED$
8+
--
9+
^warning: ignoring

0 commit comments

Comments
 (0)