Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make use of pointer::is_null #67666

Merged
merged 1 commit into from
Jan 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libpanic_unwind/emcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
let sz = mem::size_of_val(&data);
let exception = __cxa_allocate_exception(sz);
if exception == ptr::null_mut() {
if exception.is_null() {
return uw::_URC_FATAL_PHASE1_ERROR as u32;
}
ptr::write(exception as *mut _, data);
Expand Down
9 changes: 6 additions & 3 deletions src/libstd/sys/hermit/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/libstd/sys/hermit/thread_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys/sgx/abi/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl<'a> Drop for ActiveTls<'a> {
any_non_null_dtor = false;
for (value, dtor) in TLS_KEY_IN_USE.iter().filter_map(&value_with_destructor) {
let value = value.replace(ptr::null_mut());
if value != ptr::null_mut() {
if !value.is_null() {
any_non_null_dtor = true;
unsafe { dtor(value) }
}
Expand Down
10 changes: 6 additions & 4 deletions src/libstd/sys/unix/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,13 @@ pub fn env() -> Env {
let _guard = env_lock();
let mut environ = *environ();
let mut result = Vec::new();
while environ != ptr::null() && *environ != ptr::null() {
if let Some(key_value) = parse(CStr::from_ptr(*environ).to_bytes()) {
result.push(key_value);
if !environ.is_null() {
while !(*environ).is_null() {
if let Some(key_value) = parse(CStr::from_ptr(*environ).to_bytes()) {
result.push(key_value);
}
environ = environ.add(1);
}
environ = environ.offset(1);
}
return Env { iter: result.into_iter(), _dont_send_or_sync_me: PhantomData };
}
Expand Down
7 changes: 3 additions & 4 deletions src/libstd/sys/vxworks/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::marker::PhantomData;
use crate::mem;
use crate::memchr;
use crate::path::{self, Path, PathBuf};
use crate::ptr;
use crate::slice;
use crate::str;
use crate::sys::cvt;
Expand Down Expand Up @@ -226,15 +225,15 @@ pub fn env() -> Env {
unsafe {
let _guard = env_lock();
let mut environ = *environ();
if environ == ptr::null() {
if environ.is_null() {
panic!("os::env() failure getting env string from OS: {}", io::Error::last_os_error());
}
let mut result = Vec::new();
while *environ != ptr::null() {
while !(*environ).is_null() {
if let Some(key_value) = parse(CStr::from_ptr(*environ).to_bytes()) {
result.push(key_value);
}
environ = environ.offset(1);
environ = environ.add(1);
}
return Env { iter: result.into_iter(), _dont_send_or_sync_me: PhantomData };
}
Expand Down
11 changes: 6 additions & 5 deletions src/libstd/sys/wasi/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::io;
use crate::marker::PhantomData;
use crate::os::wasi::prelude::*;
use crate::path::{self, PathBuf};
use crate::ptr;
use crate::str;
use crate::sys::memchr;
use crate::sys::{unsupported, Void};
Expand Down Expand Up @@ -107,11 +106,13 @@ pub fn env() -> Env {
let _guard = env_lock();
let mut environ = libc::environ;
let mut result = Vec::new();
while environ != ptr::null_mut() && *environ != ptr::null_mut() {
if let Some(key_value) = parse(CStr::from_ptr(*environ).to_bytes()) {
result.push(key_value);
if !environ.is_null() {
while !(*environ).is_null() {
if let Some(key_value) = parse(CStr::from_ptr(*environ).to_bytes()) {
result.push(key_value);
}
environ = environ.add(1);
}
environ = environ.offset(1);
}
return Env { iter: result.into_iter(), _dont_send_or_sync_me: PhantomData };
}
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys/windows/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn error_string(mut errnum: i32) -> String {
];
module = c::GetModuleHandleW(NTDLL_DLL.as_ptr());

if module != ptr::null_mut() {
if !module.is_null() {
errnum ^= c::FACILITY_NT_BIT as i32;
flags = c::FORMAT_MESSAGE_FROM_HMODULE;
}
Expand Down