@@ -69,8 +69,6 @@ static void umf_ba_create_global(void) {
69
69
70
70
// returns index of the allocation class for a given size
71
71
static int size_to_idx (size_t size ) {
72
- assert (size <= BASE_ALLOC .ac_sizes [NUM_ALLOCATION_CLASSES - 1 ]);
73
-
74
72
if (size <= BASE_ALLOC .ac_sizes [0 ]) {
75
73
return 0 ;
76
74
}
@@ -80,8 +78,6 @@ static int size_to_idx(size_t size) {
80
78
(int )(log2Utils (size ) + !isPowerOf2 - BASE_ALLOC .smallest_ac_size_log2 );
81
79
82
80
assert (index >= 0 );
83
- assert (index < NUM_ALLOCATION_CLASSES );
84
-
85
81
return index ;
86
82
}
87
83
@@ -147,7 +143,8 @@ void *umf_ba_global_aligned_alloc(size_t size, size_t alignment) {
147
143
size += alignment ;
148
144
}
149
145
150
- if (size > BASE_ALLOC .ac_sizes [NUM_ALLOCATION_CLASSES - 1 ]) {
146
+ int ac_index = size_to_idx (size );
147
+ if (ac_index >= NUM_ALLOCATION_CLASSES ) {
151
148
#ifndef NDEBUG
152
149
fprintf (stderr ,
153
150
"base_alloc: allocation size larger than the biggest "
@@ -156,7 +153,6 @@ void *umf_ba_global_aligned_alloc(size_t size, size_t alignment) {
156
153
return add_metadata_and_align (ba_os_alloc (size ), size , alignment );
157
154
}
158
155
159
- int ac_index = size_to_idx (size );
160
156
if (!BASE_ALLOC .ac [ac_index ]) {
161
157
// if creating ac failed, fall back to os allocation
162
158
fprintf (stderr , "base_alloc: allocation class not created. Falling "
@@ -180,12 +176,12 @@ void umf_ba_global_free(void *ptr) {
180
176
size_t total_size ;
181
177
ptr = get_original_alloc (ptr , & total_size , NULL );
182
178
183
- if (total_size > BASE_ALLOC .ac_sizes [NUM_ALLOCATION_CLASSES - 1 ]) {
179
+ int ac_index = size_to_idx (total_size );
180
+ if (ac_index >= NUM_ALLOCATION_CLASSES ) {
184
181
ba_os_free (ptr , total_size );
185
182
return ;
186
183
}
187
184
188
- int ac_index = size_to_idx (total_size );
189
185
if (!BASE_ALLOC .ac [ac_index ]) {
190
186
// if creating ac failed, memory must have been allocated by os
191
187
ba_os_free (ptr , total_size );
0 commit comments