@@ -92,8 +92,8 @@ mod contents {
92
92
a. trailing_zeros ( ) as c_int
93
93
}
94
94
95
- fn align_to_flags ( align : usize ) -> c_int {
96
- if align <= MIN_ALIGN {
95
+ fn align_to_flags ( align : usize , size : usize ) -> c_int {
96
+ if align <= MIN_ALIGN && align <= size {
97
97
0
98
98
} else {
99
99
mallocx_align ( align)
@@ -111,7 +111,7 @@ mod contents {
111
111
pub unsafe extern fn __rde_alloc ( size : usize ,
112
112
align : usize ,
113
113
err : * mut u8 ) -> * mut u8 {
114
- let flags = align_to_flags ( align) ;
114
+ let flags = align_to_flags ( align, size ) ;
115
115
let ptr = mallocx ( size as size_t , flags) as * mut u8 ;
116
116
if ptr. is_null ( ) {
117
117
let layout = Layout :: from_size_align_unchecked ( size, align) ;
@@ -132,7 +132,7 @@ mod contents {
132
132
pub unsafe extern fn __rde_dealloc ( ptr : * mut u8 ,
133
133
size : usize ,
134
134
align : usize ) {
135
- let flags = align_to_flags ( align) ;
135
+ let flags = align_to_flags ( align, size ) ;
136
136
sdallocx ( ptr as * mut c_void , size, flags) ;
137
137
}
138
138
@@ -142,7 +142,7 @@ mod contents {
142
142
min : * mut usize ,
143
143
max : * mut usize ) {
144
144
let layout = & * ( layout as * const Layout ) ;
145
- let flags = align_to_flags ( layout. align ( ) ) ;
145
+ let flags = align_to_flags ( layout. align ( ) , layout . size ( ) ) ;
146
146
let size = nallocx ( layout. size ( ) , flags) as usize ;
147
147
* min = layout. size ( ) ;
148
148
if size > 0 {
@@ -166,7 +166,7 @@ mod contents {
166
166
return 0 as * mut u8
167
167
}
168
168
169
- let flags = align_to_flags ( new_align) ;
169
+ let flags = align_to_flags ( new_align, new_size ) ;
170
170
let ptr = rallocx ( ptr as * mut c_void , new_size, flags) as * mut u8 ;
171
171
if ptr. is_null ( ) {
172
172
let layout = Layout :: from_size_align_unchecked ( new_size, new_align) ;
@@ -181,10 +181,10 @@ mod contents {
181
181
pub unsafe extern fn __rde_alloc_zeroed ( size : usize ,
182
182
align : usize ,
183
183
err : * mut u8 ) -> * mut u8 {
184
- let ptr = if align <= MIN_ALIGN {
184
+ let ptr = if align <= MIN_ALIGN && align <= size {
185
185
calloc ( size as size_t , 1 ) as * mut u8
186
186
} else {
187
- let flags = align_to_flags ( align) | MALLOCX_ZERO ;
187
+ let flags = align_to_flags ( align, size ) | MALLOCX_ZERO ;
188
188
mallocx ( size as size_t , flags) as * mut u8
189
189
} ;
190
190
if ptr. is_null ( ) {
@@ -203,7 +203,7 @@ mod contents {
203
203
err : * mut u8 ) -> * mut u8 {
204
204
let p = __rde_alloc ( size, align, err) ;
205
205
if !p. is_null ( ) {
206
- let flags = align_to_flags ( align) ;
206
+ let flags = align_to_flags ( align, size ) ;
207
207
* excess = nallocx ( size, flags) as usize ;
208
208
}
209
209
return p
@@ -220,7 +220,7 @@ mod contents {
220
220
err : * mut u8 ) -> * mut u8 {
221
221
let p = __rde_realloc ( ptr, old_size, old_align, new_size, new_align, err) ;
222
222
if !p. is_null ( ) {
223
- let flags = align_to_flags ( new_align) ;
223
+ let flags = align_to_flags ( new_align, new_size ) ;
224
224
* excess = nallocx ( new_size, flags) as usize ;
225
225
}
226
226
p
@@ -244,7 +244,7 @@ mod contents {
244
244
new_size : usize ,
245
245
new_align : usize ) -> u8 {
246
246
if old_align == new_align {
247
- let flags = align_to_flags ( new_align) ;
247
+ let flags = align_to_flags ( new_align, new_size ) ;
248
248
( xallocx ( ptr as * mut c_void , new_size, 0 , flags) == new_size) as u8
249
249
} else {
250
250
0
0 commit comments