From cd9a73d2ea4ca9452e3471d7e6c04af14eb1c2ed Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 10 Jan 2020 12:52:00 +0000 Subject: make use of pointer::is_null --- src/libstd/sys/hermit/os.rs | 9 ++++++--- src/libstd/sys/hermit/thread_local.rs | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'src/libstd/sys/hermit') 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 = ptr::null_mut(); unsafe fn keys() -> &'static mut BTreeMap> { - 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 { - if LOCALS == ptr::null_mut() { + if LOCALS.is_null() { LOCALS = Box::into_raw(Box::new(BTreeMap::new())); } &mut *LOCALS -- cgit 1.4.1-3-g733a5