@@ -162,24 +162,26 @@ inline void free(void *ptr)
162
162
__CPROVER_precondition (ptr == 0 || __CPROVER_POINTER_OFFSET (ptr )== 0 ,
163
163
"free argument has offset zero" );
164
164
165
- if (ptr != 0 )
166
- {
167
- // catch double free
168
- if (__CPROVER_deallocated == ptr )
169
- __CPROVER_assert (0 , "double free" );
165
+ // catch double free
166
+ __CPROVER_precondition (ptr == 0 || __CPROVER_deallocated != ptr ,
167
+ "double free" );
170
168
171
- // catch people who try to use free(...) for stuff
172
- // allocated with new[]
173
- __CPROVER_assert (__CPROVER_malloc_object != ptr ||
174
- !__CPROVER_malloc_is_new_array ,
175
- "free called for new[] object" );
169
+ // catch people who try to use free(...) for stuff
170
+ // allocated with new[]
171
+ __CPROVER_precondition (ptr == 0 ||
172
+ __CPROVER_malloc_object != ptr ||
173
+ !__CPROVER_malloc_is_new_array ,
174
+ "free called for new[] object" );
176
175
176
+ if (ptr != 0 )
177
+ {
177
178
// non-deterministically record as deallocated
178
179
__CPROVER_bool record = __VERIFIER_nondet___CPROVER_bool ();
179
180
if (record ) __CPROVER_deallocated = ptr ;
180
181
181
182
// detect memory leaks
182
- if (__CPROVER_memory_leak == ptr ) __CPROVER_memory_leak = 0 ;
183
+ if (__CPROVER_memory_leak == ptr )
184
+ __CPROVER_memory_leak = 0 ;
183
185
}
184
186
}
185
187
@@ -206,7 +208,7 @@ inline long strtol(const char *nptr, char **endptr, int base)
206
208
{
207
209
__CPROVER_HIDE :;
208
210
#ifdef __CPROVER_STRING_ABSTRACTION
209
- __CPROVER_assert (__CPROVER_is_zero_string (nptr ),
211
+ __CPROVER_precondition (__CPROVER_is_zero_string (nptr ),
210
212
"zero-termination of argument of strtol" );
211
213
#endif
212
214
@@ -329,7 +331,7 @@ inline char *getenv(const char *name)
329
331
330
332
(void )* name ;
331
333
#ifdef __CPROVER_STRING_ABSTRACTION
332
- __CPROVER_assert (__CPROVER_is_zero_string (name ),
334
+ __CPROVER_precondition (__CPROVER_is_zero_string (name ),
333
335
"zero-termination of argument of getenv" );
334
336
#endif
335
337
@@ -367,6 +369,9 @@ inline void *realloc(void *ptr, __CPROVER_size_t malloc_size)
367
369
{
368
370
__CPROVER_HIDE :;
369
371
372
+ __CPROVER_precondition (ptr == 0 || __CPROVER_DYNAMIC_OBJECT (ptr ),
373
+ "realloc argument is dynamic object" );
374
+
370
375
// if ptr is NULL, this behaves like malloc
371
376
if (ptr == 0 )
372
377
return malloc (malloc_size );
@@ -379,9 +384,6 @@ inline void *realloc(void *ptr, __CPROVER_size_t malloc_size)
379
384
return malloc (1 );
380
385
}
381
386
382
- __CPROVER_assert (__CPROVER_DYNAMIC_OBJECT (ptr ),
383
- "realloc argument is dynamic object" );
384
-
385
387
// this shouldn't move if the new size isn't bigger
386
388
void * res ;
387
389
res = malloc (malloc_size );
0 commit comments