File tree Expand file tree Collapse file tree 5 files changed +17
-13
lines changed Expand file tree Collapse file tree 5 files changed +17
-13
lines changed Original file line number Diff line number Diff line change @@ -179,6 +179,7 @@ void ansi_c_internal_additions(std::string &code)
179
179
" void *" CPROVER_PREFIX " allocate("
180
180
CPROVER_PREFIX " size_t size, " CPROVER_PREFIX " bool zero);\n "
181
181
" const void *" CPROVER_PREFIX " alloca_object = 0;\n "
182
+ " void " CPROVER_PREFIX " deallocate(void *);\n "
182
183
183
184
CPROVER_PREFIX " size_t " CPROVER_PREFIX " max_malloc_size=" +
184
185
integer2string (max_malloc_size (config.ansi_c .pointer_width , config
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ typedef __typeof__(sizeof(int)) __CPROVER_size_t;
19
19
typedef signed long long __CPROVER_ssize_t ;
20
20
21
21
void * __CPROVER_allocate (__CPROVER_size_t size , __CPROVER_bool zero );
22
+ void __CPROVER_deallocate (void * );
22
23
extern const void * __CPROVER_deallocated ;
23
24
extern const void * __CPROVER_new_object ;
24
25
extern __CPROVER_bool __CPROVER_malloc_is_new_array ;
Original file line number Diff line number Diff line change @@ -112,8 +112,7 @@ int munmap(void *addr, __CPROVER_size_t length)
112
112
{
113
113
(void )length ;
114
114
115
- if (__VERIFIER_nondet___CPROVER_bool ())
116
- __CPROVER_deallocated = addr ;
115
+ __CPROVER_deallocate (addr );
117
116
118
117
return 0 ;
119
118
}
@@ -126,8 +125,7 @@ int _munmap(void *addr, __CPROVER_size_t length)
126
125
{
127
126
(void )length ;
128
127
129
- if (__VERIFIER_nondet___CPROVER_bool ())
130
- __CPROVER_deallocated = addr ;
128
+ __CPROVER_deallocate (addr );
131
129
132
130
return 0 ;
133
131
}
Original file line number Diff line number Diff line change @@ -271,9 +271,7 @@ inline void free(void *ptr)
271
271
272
272
if (ptr != 0 )
273
273
{
274
- // non-deterministically record as deallocated
275
- __CPROVER_bool record = __VERIFIER_nondet___CPROVER_bool ();
276
- if (record ) __CPROVER_deallocated = ptr ;
274
+ __CPROVER_deallocate (ptr );
277
275
278
276
// detect memory leaks
279
277
if (__CPROVER_memory_leak == ptr )
@@ -590,3 +588,13 @@ __CPROVER_HIDE:;
590
588
__CPROVER_assume (result >= 0 );
591
589
return result ;
592
590
}
591
+
592
+ /* FUNCTION: __CPROVER_deallocate */
593
+
594
+ __CPROVER_bool __VERIFIER_nondet___CPROVER_bool ();
595
+
596
+ void __CPROVER_deallocate (void * ptr )
597
+ {
598
+ if (__VERIFIER_nondet___CPROVER_bool ())
599
+ __CPROVER_deallocated = ptr ;
600
+ }
Original file line number Diff line number Diff line change @@ -88,9 +88,7 @@ inline void __delete(void *ptr)
88
88
// This is a requirement by the standard, not generosity!
89
89
if (ptr != 0 )
90
90
{
91
- // non-deterministically record as deallocated
92
- __CPROVER_bool record = __VERIFIER_nondet___CPROVER_bool ();
93
- __CPROVER_deallocated = record ?ptr :__CPROVER_deallocated ;
91
+ __CPROVER_deallocate (ptr );
94
92
95
93
// detect memory leaks
96
94
if (__CPROVER_memory_leak == ptr )
@@ -125,9 +123,7 @@ inline void __delete_array(void *ptr)
125
123
126
124
if (ptr != 0 )
127
125
{
128
- // non-deterministically record as deallocated
129
- __CPROVER_bool record = __VERIFIER_nondet___CPROVER_bool ();
130
- __CPROVER_deallocated = record ?ptr :__CPROVER_deallocated ;
126
+ __CPROVER_deallocate (ptr );
131
127
132
128
// detect memory leaks
133
129
if (__CPROVER_memory_leak == ptr ) __CPROVER_memory_leak = 0 ;
You can’t perform that action at this time.
0 commit comments