@@ -65,9 +65,17 @@ __CPROVER_bool __VERIFIER_nondet___CPROVER_bool();
65
65
66
66
inline void * calloc (__CPROVER_size_t nmemb , __CPROVER_size_t size )
67
67
{
68
- // realistically, calloc may return NULL,
69
- // and __CPROVER_allocate doesn't, but no one cares
70
- __CPROVER_HIDE :;
68
+ // realistically, calloc may return NULL,
69
+ // and __CPROVER_allocate doesn't, but no one cares
70
+
71
+ __CPROVER_HIDE :;
72
+
73
+ // ensure that all bytes in the allocated memory can be addressed
74
+ // using our object:offset encoding as specified in
75
+ // flattening/pointer_logic.h; also avoid sign-extension issues
76
+ // for 32-bit systems that yields a maximum allocation of 2^23-1,
77
+ // i.e., just under 8MB
78
+ __CPROVER_assume (nmemb * size < (1ULL << ((sizeof (char * ) - 1 ) * 8 - 1 )));
71
79
void * malloc_res ;
72
80
malloc_res = __CPROVER_allocate (nmemb * size , 1 );
73
81
@@ -104,8 +112,16 @@ __CPROVER_bool __VERIFIER_nondet___CPROVER_bool();
104
112
inline void * malloc (__CPROVER_size_t malloc_size )
105
113
{
106
114
// realistically, malloc may return NULL,
107
- // and __CPROVER_allocate doesn't, but no one cares
108
- __CPROVER_HIDE :;
115
+ // and __CPROVER_allocate doesn't, but no one cares
116
+
117
+ __CPROVER_HIDE :;
118
+
119
+ // ensure that all bytes in the allocated memory can be addressed
120
+ // using our object:offset encoding as specified in
121
+ // flattening/pointer_logic.h; also avoid sign-extension issues
122
+ // for 32-bit systems that yields a maximum allocation of 2^23-1,
123
+ // i.e., just under 8MB
124
+ __CPROVER_assume (malloc_size < (1ULL << ((sizeof (char * ) - 1 ) * 8 - 1 )));
109
125
void * malloc_res ;
110
126
malloc_res = __CPROVER_allocate (malloc_size , 0 );
111
127
@@ -131,18 +147,27 @@ __CPROVER_bool __VERIFIER_nondet___CPROVER_bool();
131
147
132
148
inline void * __builtin_alloca (__CPROVER_size_t alloca_size )
133
149
{
134
- __CPROVER_HIDE :;
150
+ __CPROVER_HIDE :;
151
+
152
+ // ensure that all bytes in the allocated memory can be addressed
153
+ // using our object:offset encoding as specified in
154
+ // flattening/pointer_logic.h; also avoid sign-extension issues
155
+ // for 32-bit systems that yields a maximum allocation of 2^23-1,
156
+ // i.e., just under 8MB
157
+ __CPROVER_assume (alloca_size < (1ULL << ((sizeof (char * ) - 1 ) * 8 - 1 )));
135
158
void * res ;
136
159
res = __CPROVER_allocate (alloca_size , 0 );
137
160
138
161
// make sure it's not recorded as deallocated
139
- __CPROVER_deallocated = (res == __CPROVER_deallocated )?0 :__CPROVER_deallocated ;
162
+ __CPROVER_deallocated =
163
+ (res == __CPROVER_deallocated ) ? 0 : __CPROVER_deallocated ;
140
164
141
165
// record the object size for non-determistic bounds checking
142
- __CPROVER_bool record_malloc = __VERIFIER_nondet___CPROVER_bool ();
143
- __CPROVER_malloc_object = record_malloc ?res :__CPROVER_malloc_object ;
144
- __CPROVER_malloc_size = record_malloc ?alloca_size :__CPROVER_malloc_size ;
145
- __CPROVER_malloc_is_new_array = record_malloc ?0 :__CPROVER_malloc_is_new_array ;
166
+ __CPROVER_bool record_malloc = __VERIFIER_nondet___CPROVER_bool ();
167
+ __CPROVER_malloc_object = record_malloc ? res : __CPROVER_malloc_object ;
168
+ __CPROVER_malloc_size = record_malloc ? alloca_size : __CPROVER_malloc_size ;
169
+ __CPROVER_malloc_is_new_array =
170
+ record_malloc ? 0 : __CPROVER_malloc_is_new_array ;
146
171
147
172
return res ;
148
173
}
0 commit comments