@@ -72,30 +72,32 @@ __CPROVER_bool __VERIFIER_nondet___CPROVER_bool();
72
72
inline void __delete (void * ptr )
73
73
{
74
74
__CPROVER_HIDE :;
75
+ // is it dynamic?
76
+ __CPROVER_precondition (ptr == 0 || __CPROVER_DYNAMIC_OBJECT (ptr ),
77
+ "delete argument must be dynamic object" );
78
+ __CPROVER_precondition (__CPROVER_POINTER_OFFSET (ptr )== 0 ,
79
+ "delete argument must have offset zero" );
80
+
81
+ // catch double delete
82
+ __CPROVER_precondition (ptr == 0 || __CPROVER_deallocated != ptr , "double delete" );
83
+
84
+ // catch people who call delete for objects allocated with new[]
85
+ __CPROVER_precondition (ptr == 0 ||
86
+ __CPROVER_malloc_object != ptr ||
87
+ !__CPROVER_malloc_is_new_array ,
88
+ "delete of array object" );
89
+
75
90
// If ptr is NULL, no operation is performed.
76
91
// This is a requirement by the standard, not generosity!
77
92
if (ptr != 0 )
78
93
{
79
- // is it dynamic?
80
- __CPROVER_assert (__CPROVER_DYNAMIC_OBJECT (ptr ),
81
- "delete argument must be dynamic object" );
82
- __CPROVER_assert (__CPROVER_POINTER_OFFSET (ptr )== 0 ,
83
- "delete argument must have offset zero" );
84
-
85
- // catch double delete
86
- __CPROVER_assert (__CPROVER_deallocated != ptr , "double delete" );
87
-
88
- // catch people who call delete for objects allocated with new[]
89
- __CPROVER_assert (__CPROVER_malloc_object != ptr ||
90
- !__CPROVER_malloc_is_new_array ,
91
- "delete of array object" );
92
-
93
94
// non-deterministically record as deallocated
94
95
__CPROVER_bool record = __VERIFIER_nondet___CPROVER_bool ();
95
96
__CPROVER_deallocated = record ?ptr :__CPROVER_deallocated ;
96
97
97
98
// detect memory leaks
98
- if (__CPROVER_memory_leak == ptr ) __CPROVER_memory_leak = 0 ;
99
+ if (__CPROVER_memory_leak == ptr )
100
+ __CPROVER_memory_leak = 0 ;
99
101
}
100
102
}
101
103
@@ -108,22 +110,25 @@ inline void __delete_array(void *ptr)
108
110
__CPROVER_HIDE :;
109
111
// If ptr is NULL, no operation is performed.
110
112
// This is a requirement by the standard, not generosity!
111
- if (ptr != 0 )
112
- {
113
- // is it dynamic?
114
- __CPROVER_assert (__CPROVER_DYNAMIC_OBJECT (ptr ),
115
- "delete argument must be dynamic object" );
116
- __CPROVER_assert (__CPROVER_POINTER_OFFSET (ptr )== 0 ,
117
- "delete argument must have offset zero" );
118
113
119
- // catch double delete
120
- __CPROVER_assert (__CPROVER_deallocated != ptr , "double delete" );
114
+ // is it dynamic?
115
+ __CPROVER_precondition (ptr == 0 || __CPROVER_DYNAMIC_OBJECT (ptr ),
116
+ "delete argument must be dynamic object" );
117
+ __CPROVER_precondition (ptr == 0 || __CPROVER_POINTER_OFFSET (ptr )== 0 ,
118
+ "delete argument must have offset zero" );
121
119
122
- // catch people who call delete[] for objects allocated with new
123
- __CPROVER_assert (__CPROVER_malloc_object != ptr ||
124
- __CPROVER_malloc_is_new_array ,
125
- "delete[] of non-array object" );
120
+ // catch double delete
121
+ __CPROVER_precondition (ptr == 0 || __CPROVER_deallocated != ptr ,
122
+ "double delete" );
126
123
124
+ // catch people who call delete[] for objects allocated with new
125
+ __CPROVER_precondition (ptr == 0 ||
126
+ __CPROVER_malloc_object != ptr ||
127
+ __CPROVER_malloc_is_new_array ,
128
+ "delete[] of non-array object" );
129
+
130
+ if (ptr != 0 )
131
+ {
127
132
// non-deterministically record as deallocated
128
133
__CPROVER_bool record = __VERIFIER_nondet___CPROVER_bool ();
129
134
__CPROVER_deallocated = record ?ptr :__CPROVER_deallocated ;
0 commit comments