]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/fail/environ-gets-deallocated.rs
Merge commit 'd822110d3b5625b9dc80ccc442e06fc3cc851d76' into clippyup
[rust.git] / src / tools / miri / tests / fail / environ-gets-deallocated.rs
1 //@ignore-target-windows: Windows does not have a global environ list that the program can access directly
2
3 #[cfg(any(target_os = "linux", target_os = "freebsd"))]
4 fn get_environ() -> *const *const u8 {
5     extern "C" {
6         static mut environ: *const *const u8;
7     }
8     unsafe { environ }
9 }
10
11 #[cfg(target_os = "macos")]
12 fn get_environ() -> *const *const u8 {
13     extern "C" {
14         fn _NSGetEnviron() -> *mut *const *const u8;
15     }
16     unsafe { *_NSGetEnviron() }
17 }
18
19 fn main() {
20     let pointer = get_environ();
21     let _x = unsafe { *pointer };
22     std::env::set_var("FOO", "BAR");
23     let _y = unsafe { *pointer }; //~ ERROR: dereferenced after this allocation got freed
24 }