Skip to content

Commit 2db8c45

Browse files
authored
Merge pull request #982 from tautschnig/pointer-handling
Fixes and improvements to dynamic memory handling
2 parents 0361c2a + fb532e8 commit 2db8c45

36 files changed

+218
-93
lines changed

regression/cbmc-with-incr/Malloc17/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ unsigned char* init1()
44
if (size!=1) return 0;
55

66
assert(sizeof(unsigned char)==1);
7-
unsigned char* buffer=__CPROVER_malloc(1);
7+
unsigned char* buffer=__CPROVER_allocate(1, 0);
88
assert(buffer!=0);
99

1010
buffer[0]=0;
@@ -18,7 +18,7 @@ unsigned char* init2()
1818
if (size!=1) return 0;
1919

2020
assert(sizeof(unsigned char)==1);
21-
unsigned char* buffer=__CPROVER_malloc(1*sizeof(unsigned char));
21+
unsigned char* buffer=__CPROVER_allocate(1*sizeof(unsigned char), 0);
2222
assert(buffer!=0);
2323

2424
buffer[0]=0;
@@ -32,7 +32,7 @@ unsigned char* init3()
3232
if (size!=1) return 0;
3333

3434
assert(sizeof(unsigned char)==1);
35-
unsigned char* buffer=__CPROVER_malloc(sizeof(unsigned char)*1);
35+
unsigned char* buffer=__CPROVER_allocate(sizeof(unsigned char)*1, 0);
3636
assert(buffer!=0);
3737

3838
buffer[0]=0;

regression/cbmc-with-incr/Malloc18/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ unsigned char* init()
44
if (size!=1) return 0;
55

66
assert(sizeof(unsigned char)==1);
7-
unsigned char* buffer=__CPROVER_malloc(size);
7+
unsigned char* buffer=__CPROVER_allocate(size, 0);
88
assert(buffer!=0);
99

1010
buffer[0]=0;

regression/cbmc-with-incr/Malloc19/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ int main()
2222
{
2323
// Create node
2424
struct node *nd;
25-
nd = (struct node *)__CPROVER_malloc(sizeof(struct node));
25+
nd = (struct node *)__CPROVER_allocate(sizeof(struct node), 0);
2626

2727
// Link node
2828
struct list_head *hd = &(nd->linkage);

regression/cbmc/Calloc1/main.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <stdlib.h>
2+
#include <assert.h>
3+
4+
int main()
5+
{
6+
int *x=calloc(sizeof(int), 1);
7+
assert(*x==0);
8+
return 0;
9+
}

regression/cbmc/Calloc1/test.desc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

regression/cbmc/Malloc17/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ unsigned char* init1()
44
if (size!=1) return 0;
55

66
assert(sizeof(unsigned char)==1);
7-
unsigned char* buffer=__CPROVER_malloc(1);
7+
unsigned char* buffer=__CPROVER_allocate(1, 0);
88
assert(buffer!=0);
99

1010
buffer[0]=0;
@@ -18,7 +18,7 @@ unsigned char* init2()
1818
if (size!=1) return 0;
1919

2020
assert(sizeof(unsigned char)==1);
21-
unsigned char* buffer=__CPROVER_malloc(1*sizeof(unsigned char));
21+
unsigned char* buffer=__CPROVER_allocate(1*sizeof(unsigned char), 0);
2222
assert(buffer!=0);
2323

2424
buffer[0]=0;
@@ -32,7 +32,7 @@ unsigned char* init3()
3232
if (size!=1) return 0;
3333

3434
assert(sizeof(unsigned char)==1);
35-
unsigned char* buffer=__CPROVER_malloc(sizeof(unsigned char)*1);
35+
unsigned char* buffer=__CPROVER_allocate(sizeof(unsigned char)*1, 0);
3636
assert(buffer!=0);
3737

3838
buffer[0]=0;

regression/cbmc/Malloc18/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ unsigned char* init()
33
unsigned long buffer_size;
44
if(buffer_size!=1) return 0;
55

6-
unsigned char* buffer=__CPROVER_malloc(buffer_size);
6+
unsigned char* buffer=__CPROVER_allocate(buffer_size, 0);
77
__CPROVER_assert(buffer!=0, "malloc did not return NULL");
88

99
buffer[0]=10;

regression/cbmc/Malloc19/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ int main()
2222
{
2323
// Create node
2424
struct node *nd;
25-
nd = (struct node *)__CPROVER_malloc(sizeof(struct node));
25+
nd = (struct node *)__CPROVER_allocate(sizeof(struct node), 0);
2626

2727
// Link node
2828
struct list_head *hd = &(nd->linkage);

regression/cbmc/Malloc24/main.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include <stdlib.h>
2+
3+
struct node
4+
{
5+
int value;
6+
struct node *next;
7+
};
8+
9+
struct list
10+
{
11+
int size;
12+
struct node *head;
13+
};
14+
15+
void removeLast(struct list * l)
16+
{
17+
int index = l->size - 1;
18+
struct node **current;
19+
for(current = &(l->head); index && *current; index--)
20+
current = &(*current)->next;
21+
*current = (*current)->next;
22+
l->size--;
23+
}
24+
25+
int main () {
26+
//build a 2-nodes list
27+
struct node *n0 = malloc(sizeof(struct node));
28+
struct node *n1 = malloc(sizeof(struct node));
29+
struct list *l = malloc(sizeof(struct list));
30+
l->size = 2;
31+
l->head = n0;
32+
33+
n0->next=n1;
34+
n1->next=NULL;
35+
36+
//remove last node from list
37+
38+
//this passes
39+
// struct node **current = &(l->head);
40+
// current = &(*current)->next;
41+
// *current = (*current)->next;
42+
// l->size--;
43+
//this doesn't
44+
removeLast(l);
45+
46+
__CPROVER_assert(n0->next == NULL , "not NULL");
47+
}

regression/cbmc/Malloc24/test.desc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--unwind 4 --pointer-check --unwinding-assertions
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

0 commit comments

Comments
 (0)