MCPcopy Create free account
hub / github.com/dropbox/rust-alloc-no-stdlib / uninitialized_stack_pool_test

Function uninitialized_stack_pool_test

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

Source from the content-addressed store, hash-verified

32}
33#[test]
34fn uninitialized_stack_pool_test() {
35 {
36 let mut stack_global_buffer = define_allocator_memory_pool!(4, u8, [0; 65536], stack);
37 let mut ags = StackAllocatedFreelist4::<u8>::new_allocator(&mut stack_global_buffer, uninitialized);
38 {
39 let mut x = ags.alloc_cell(9999);
40 x.slice_mut()[0] = 4;
41 let mut y = ags.alloc_cell(4);
42 y[0] = 5;
43 ags.free_cell(y);
44
45 let mut three = ags.alloc_cell(3);
46 three[0] = 6;
47 ags.free_cell(three);
48
49 let mut z = ags.alloc_cell(4);
50 z.slice_mut()[1] = 8;
51 let mut reget_three = ags.alloc_cell(4);
52 reget_three.slice_mut()[1] = 9;
53 //y.mem[0] = 6; // <-- this is an error (use after free)
54 assert_eq!(x[0], 4);
55 assert_eq!(z[0], 6);
56 assert_eq!(z[1], 8);
57 assert_eq!(reget_three[0], 0);
58 assert_eq!(reget_three[1], 9);
59 let mut _z = ags.alloc_cell(1);
60 }
61 }
62}
63#[test]
64fn uninitialized_stack_pool_free_null() {
65 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