MCPcopy Index your code
hub / github.com/dropbox/rust-alloc-no-stdlib / stack_pool_test

Function stack_pool_test

alloc-stdlib/tests/lib.rs:233–261  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

231
232#[test]
233fn stack_pool_test() {
234 {
235 let mut stack_global_buffer = define_allocator_memory_pool!(4, u8, [0; 65536], stack);
236 let mut ags = StackAllocatedFreelist4::<u8>::new_allocator(&mut stack_global_buffer, bzero);
237 {
238 let mut x = ags.alloc_cell(9999);
239 x.slice_mut()[0] = 4;
240 let mut y = ags.alloc_cell(4);
241 y[0] = 5;
242 ags.free_cell(y);
243
244 let mut three = ags.alloc_cell(3);
245 three[0] = 6;
246 ags.free_cell(three);
247
248 let mut z = ags.alloc_cell(4);
249 z.slice_mut()[1] = 8;
250 let mut reget_three = ags.alloc_cell(4);
251 reget_three.slice_mut()[1] = 9;
252 //y.mem[0] = 6; // <-- this is an error (use after free)
253 assert_eq!(x[0], 4);
254 assert_eq!(z[0], 0);
255 assert_eq!(z[1], 8);
256 assert_eq!(reget_three[0], 0);
257 assert_eq!(reget_three[1], 9);
258 let mut _z = ags.alloc_cell(1);
259 }
260 }
261}
262#[test]
263fn stack_pool_free_null() {
264 let mut stack_global_buffer = define_allocator_memory_pool!(8, u8, [0; 256 - 8], stack);

Callers

nothing calls this directly

Calls 3

alloc_cellMethod · 0.45
slice_mutMethod · 0.45
free_cellMethod · 0.45

Tested by

no test coverage detected