diff options
| author | Lzu Tao <taolzu@gmail.com> | 2020-01-10 12:52:00 +0000 |
|---|---|---|
| committer | Lzu Tao <taolzu@gmail.com> | 2020-01-10 12:52:00 +0000 |
| commit | cd9a73d2ea4ca9452e3471d7e6c04af14eb1c2ed (patch) | |
| tree | 9cc6c46767976077aa615a3c8311a72201fbf376 /src/libstd/sys/hermit | |
| parent | 2d8d559bbecf6272eb41f8a800e319238aa9d621 (diff) | |
| download | rust-cd9a73d2ea4ca9452e3471d7e6c04af14eb1c2ed.tar.gz rust-cd9a73d2ea4ca9452e3471d7e6c04af14eb1c2ed.zip | |
make use of pointer::is_null
Diffstat (limited to 'src/libstd/sys/hermit')
| -rw-r--r-- | src/libstd/sys/hermit/os.rs | 9 | ||||
| -rw-r--r-- | src/libstd/sys/hermit/thread_local.rs | 4 |
2 files changed, 8 insertions, 5 deletions
diff --git a/src/libstd/sys/hermit/os.rs b/src/libstd/sys/hermit/os.rs index 5999fdd4f8d..78eabf8f81e 100644 --- a/src/libstd/sys/hermit/os.rs +++ b/src/libstd/sys/hermit/os.rs @@ -6,7 +6,6 @@ use crate::io; use crate::marker::PhantomData; use crate::memchr; use crate::path::{self, PathBuf}; -use crate::ptr; use crate::str; use crate::sync::Mutex; use crate::sys::hermit::abi; @@ -77,13 +76,17 @@ pub fn init_environment(env: *const *const i8) { unsafe { ENV = Some(Mutex::new(HashMap::new())); + if env.is_null() { + return; + } + let mut guard = ENV.as_ref().unwrap().lock().unwrap(); let mut environ = env; - while environ != ptr::null() && *environ != ptr::null() { + while !(*environ).is_null() { if let Some((key, value)) = parse(CStr::from_ptr(*environ).to_bytes()) { guard.insert(key, value); } - environ = environ.offset(1); + environ = environ.add(1); } } diff --git a/src/libstd/sys/hermit/thread_local.rs b/src/libstd/sys/hermit/thread_local.rs index ba967c7676c..c6f8adb2162 100644 --- a/src/libstd/sys/hermit/thread_local.rs +++ b/src/libstd/sys/hermit/thread_local.rs @@ -18,14 +18,14 @@ static KEYS_LOCK: Mutex = Mutex::new(); static mut LOCALS: *mut BTreeMap<Key, *mut u8> = ptr::null_mut(); unsafe fn keys() -> &'static mut BTreeMap<Key, Option<Dtor>> { - if KEYS == ptr::null_mut() { + if KEYS.is_null() { KEYS = Box::into_raw(Box::new(BTreeMap::new())); } &mut *KEYS } unsafe fn locals() -> &'static mut BTreeMap<Key, *mut u8> { - if LOCALS == ptr::null_mut() { + if LOCALS.is_null() { LOCALS = Box::into_raw(Box::new(BTreeMap::new())); } &mut *LOCALS |
