File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -75,6 +75,31 @@ __CPROVER_HIDE:;
75
75
__CPROVER_size_t alloc_size = nmemb * size ;
76
76
#pragma CPROVER check pop
77
77
78
+ if (__CPROVER_malloc_failure_mode == __CPROVER_malloc_failure_mode_return_null )
79
+ {
80
+ __CPROVER_bool should_malloc_fail = __VERIFIER_nondet___CPROVER_bool ();
81
+ if (
82
+ alloc_size > __CPROVER_max_malloc_size ||
83
+ (__CPROVER_malloc_may_fail && should_malloc_fail ))
84
+ {
85
+ return (void * )0 ;
86
+ }
87
+ }
88
+ else if (
89
+ __CPROVER_malloc_failure_mode ==
90
+ __CPROVER_malloc_failure_mode_assert_then_assume )
91
+ {
92
+ __CPROVER_assert (
93
+ alloc_size <= __CPROVER_max_malloc_size , "max allocation size exceeded" );
94
+ __CPROVER_assume (alloc_size <= __CPROVER_max_malloc_size );
95
+
96
+ __CPROVER_bool should_malloc_fail = __VERIFIER_nondet___CPROVER_bool ();
97
+ __CPROVER_assert (
98
+ !__CPROVER_malloc_may_fail || !should_malloc_fail ,
99
+ "max allocation may fail" );
100
+ __CPROVER_assume (!__CPROVER_malloc_may_fail || !should_malloc_fail );
101
+ }
102
+
78
103
void * malloc_res ;
79
104
// realistically, calloc may return NULL,
80
105
// and __CPROVER_allocate doesn't, but no one cares
You can’t perform that action at this time.
0 commit comments