Skip to content

Commit 18a71ef

Browse files
committed
minor corrections
1 parent e31b8b3 commit 18a71ef

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

src/eval.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
7878
);
7979
// Complete initialization.
8080
MemoryExtra::init_extern_statics(&mut ecx)?;
81-
EnvVars::init(&mut ecx, config.excluded_env_vars);
81+
EnvVars::init(&mut ecx, config.excluded_env_vars)?;
8282

8383
// Setup first stack-frame
8484
let main_instance = ty::Instance::mono(tcx, main_id);

src/machine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub struct MemoryExtra<'tcx> {
8585
/// (helps for debugging memory leaks).
8686
tracked_alloc_id: Option<AllocId>,
8787

88-
/// Place where the `environ` static is stored. Its value should not change after initialization.
88+
/// Place where the `environ` static is stored. Lazily initialized, but then never changes.
8989
pub(crate) environ: Option<MPlaceTy<'tcx, Tag>>,
9090
}
9191

src/shims/env.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl EnvVars {
2020
pub(crate) fn init<'mir, 'tcx>(
2121
ecx: &mut InterpCx<'mir, 'tcx, Evaluator<'tcx>>,
2222
excluded_env_vars: Vec<String>,
23-
) {
23+
) -> InterpResult<'tcx> {
2424
if ecx.machine.communicate {
2525
for (name, value) in env::vars() {
2626
if !excluded_env_vars.contains(&name) {
@@ -30,7 +30,7 @@ impl EnvVars {
3030
}
3131
}
3232
}
33-
ecx.update_environ().unwrap();
33+
ecx.update_environ()
3434
}
3535
}
3636

tests/compile-fail/environ-gets-deallocated.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
1-
extern "C" {
1+
//ignore-windows: TODO env var emulation stubbed out on Windows
2+
3+
#[cfg(target_os="linux")]
4+
fn get_environ() -> *const *const u8 {
5+
extern "C" {
26
static environ: *const *const u8;
7+
}
8+
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() }
317
}
418

519
fn main() {
6-
let pointer = unsafe { environ };
20+
let pointer = get_environ();
721
let _x = unsafe { *pointer };
822
std::env::set_var("FOO", "BAR");
923
let _y = unsafe { *pointer }; //~ ERROR dangling pointer was dereferenced

0 commit comments

Comments
 (0)