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

Function uninitialized_heap_pool_test

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

Source from the content-addressed store, hash-verified

136#[test]
137#[cfg(all(feature="unsafe",not(feature="no-stdlib")))]
138fn uninitialized_heap_pool_test() {
139 {
140 let mut heap_global_buffer = unsafe{HeapPrealloc::<u8>::new_uninitialized_memory_pool(6 * 1024 * 1024)};
141 let mut ags = HeapPrealloc::<u8>::new_allocator(4096, &mut heap_global_buffer, uninitialized);
142 {
143 let mut x = ags.alloc_cell(9999);
144 x.slice_mut()[0] = 4;
145 let mut y = ags.alloc_cell(4);
146 y[0] = 5;
147 ags.free_cell(y);
148
149 let mut three = ags.alloc_cell(3);
150 three[0] = 6;
151 ags.free_cell(three);
152
153 let mut z = ags.alloc_cell(4);
154 z.slice_mut()[1] = 8;
155 let mut reget_three = ags.alloc_cell(4);
156 reget_three.slice_mut()[1] = 9;
157 //y.mem[0] = 6; // <-- this is an error (use after free)
158 assert_eq!(x[0], 4);
159 assert_eq!(z[0], 6);
160 assert_eq!(z[1], 8);
161 // assert_eq!(reget_three[0], 0); // not valid: uninitialized heap memory
162 assert_eq!(reget_three[1], 9);
163 let mut _z = ags.alloc_cell(1);
164 }
165 }
166}
167#[test]
168fn uninitialized_calloc_pool_test() {
169

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