Skip to content

Commit 6518bcb

Browse files
committed
Fix unsafe_op_in_unsafe_fn for Unix env
1 parent 90fe280 commit 6518bcb

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

library/std/src/sys/env/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Platform-dependent environment variables abstraction.
22
3-
#![deny(unsafe_op_in_unsafe_fn)]
3+
#![forbid(unsafe_op_in_unsafe_fn)]
44

55
cfg_if::cfg_if! {
66
if #[cfg(target_family = "unix")] {

library/std/src/sys/env/unix.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![allow(unsafe_op_in_unsafe_fn)]
2-
31
use core::slice::memchr;
42

53
use libc::c_char;
@@ -81,7 +79,7 @@ impl Iterator for Env {
8179
// desirable anyhow? Though it also means that we have to link to Foundation.
8280
#[cfg(target_vendor = "apple")]
8381
pub unsafe fn environ() -> *mut *const *const c_char {
84-
libc::_NSGetEnviron() as *mut *const *const c_char
82+
unsafe { libc::_NSGetEnviron() as *mut *const *const c_char }
8583
}
8684

8785
// Use the `environ` static which is part of POSIX.
@@ -159,14 +157,14 @@ pub unsafe fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> {
159157
run_with_cstr(k.as_bytes(), &|k| {
160158
run_with_cstr(v.as_bytes(), &|v| {
161159
let _guard = ENV_LOCK.write();
162-
cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(drop)
160+
cvt(unsafe { libc::setenv(k.as_ptr(), v.as_ptr(), 1) }).map(drop)
163161
})
164162
})
165163
}
166164

167165
pub unsafe fn unsetenv(n: &OsStr) -> io::Result<()> {
168166
run_with_cstr(n.as_bytes(), &|nbuf| {
169167
let _guard = ENV_LOCK.write();
170-
cvt(libc::unsetenv(nbuf.as_ptr())).map(drop)
168+
cvt(unsafe { libc::unsetenv(nbuf.as_ptr()) }).map(drop)
171169
})
172170
}

0 commit comments

Comments
 (0)