Skip to content

Commit cd9a73d

Browse files
committed
make use of pointer::is_null
1 parent 2d8d559 commit cd9a73d

File tree

8 files changed

+26
-21
lines changed

8 files changed

+26
-21
lines changed

src/libpanic_unwind/emcc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
6363
pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
6464
let sz = mem::size_of_val(&data);
6565
let exception = __cxa_allocate_exception(sz);
66-
if exception == ptr::null_mut() {
66+
if exception.is_null() {
6767
return uw::_URC_FATAL_PHASE1_ERROR as u32;
6868
}
6969
ptr::write(exception as *mut _, data);

src/libstd/sys/hermit/os.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::io;
66
use crate::marker::PhantomData;
77
use crate::memchr;
88
use crate::path::{self, PathBuf};
9-
use crate::ptr;
109
use crate::str;
1110
use crate::sync::Mutex;
1211
use crate::sys::hermit::abi;
@@ -77,13 +76,17 @@ pub fn init_environment(env: *const *const i8) {
7776
unsafe {
7877
ENV = Some(Mutex::new(HashMap::new()));
7978

79+
if env.is_null() {
80+
return;
81+
}
82+
8083
let mut guard = ENV.as_ref().unwrap().lock().unwrap();
8184
let mut environ = env;
82-
while environ != ptr::null() && *environ != ptr::null() {
85+
while !(*environ).is_null() {
8386
if let Some((key, value)) = parse(CStr::from_ptr(*environ).to_bytes()) {
8487
guard.insert(key, value);
8588
}
86-
environ = environ.offset(1);
89+
environ = environ.add(1);
8790
}
8891
}
8992

src/libstd/sys/hermit/thread_local.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ static KEYS_LOCK: Mutex = Mutex::new();
1818
static mut LOCALS: *mut BTreeMap<Key, *mut u8> = ptr::null_mut();
1919

2020
unsafe fn keys() -> &'static mut BTreeMap<Key, Option<Dtor>> {
21-
if KEYS == ptr::null_mut() {
21+
if KEYS.is_null() {
2222
KEYS = Box::into_raw(Box::new(BTreeMap::new()));
2323
}
2424
&mut *KEYS
2525
}
2626

2727
unsafe fn locals() -> &'static mut BTreeMap<Key, *mut u8> {
28-
if LOCALS == ptr::null_mut() {
28+
if LOCALS.is_null() {
2929
LOCALS = Box::into_raw(Box::new(BTreeMap::new()));
3030
}
3131
&mut *LOCALS

src/libstd/sys/sgx/abi/tls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl<'a> Drop for ActiveTls<'a> {
7070
any_non_null_dtor = false;
7171
for (value, dtor) in TLS_KEY_IN_USE.iter().filter_map(&value_with_destructor) {
7272
let value = value.replace(ptr::null_mut());
73-
if value != ptr::null_mut() {
73+
if !value.is_null() {
7474
any_non_null_dtor = true;
7575
unsafe { dtor(value) }
7676
}

src/libstd/sys/unix/os.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -480,11 +480,13 @@ pub fn env() -> Env {
480480
let _guard = env_lock();
481481
let mut environ = *environ();
482482
let mut result = Vec::new();
483-
while environ != ptr::null() && *environ != ptr::null() {
484-
if let Some(key_value) = parse(CStr::from_ptr(*environ).to_bytes()) {
485-
result.push(key_value);
483+
if !environ.is_null() {
484+
while !(*environ).is_null() {
485+
if let Some(key_value) = parse(CStr::from_ptr(*environ).to_bytes()) {
486+
result.push(key_value);
487+
}
488+
environ = environ.add(1);
486489
}
487-
environ = environ.offset(1);
488490
}
489491
return Env { iter: result.into_iter(), _dont_send_or_sync_me: PhantomData };
490492
}

src/libstd/sys/vxworks/os.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use crate::marker::PhantomData;
77
use crate::mem;
88
use crate::memchr;
99
use crate::path::{self, Path, PathBuf};
10-
use crate::ptr;
1110
use crate::slice;
1211
use crate::str;
1312
use crate::sys::cvt;
@@ -226,15 +225,15 @@ pub fn env() -> Env {
226225
unsafe {
227226
let _guard = env_lock();
228227
let mut environ = *environ();
229-
if environ == ptr::null() {
228+
if environ.is_null() {
230229
panic!("os::env() failure getting env string from OS: {}", io::Error::last_os_error());
231230
}
232231
let mut result = Vec::new();
233-
while *environ != ptr::null() {
232+
while !(*environ).is_null() {
234233
if let Some(key_value) = parse(CStr::from_ptr(*environ).to_bytes()) {
235234
result.push(key_value);
236235
}
237-
environ = environ.offset(1);
236+
environ = environ.add(1);
238237
}
239238
return Env { iter: result.into_iter(), _dont_send_or_sync_me: PhantomData };
240239
}

src/libstd/sys/wasi/os.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::io;
66
use crate::marker::PhantomData;
77
use crate::os::wasi::prelude::*;
88
use crate::path::{self, PathBuf};
9-
use crate::ptr;
109
use crate::str;
1110
use crate::sys::memchr;
1211
use crate::sys::{unsupported, Void};
@@ -107,11 +106,13 @@ pub fn env() -> Env {
107106
let _guard = env_lock();
108107
let mut environ = libc::environ;
109108
let mut result = Vec::new();
110-
while environ != ptr::null_mut() && *environ != ptr::null_mut() {
111-
if let Some(key_value) = parse(CStr::from_ptr(*environ).to_bytes()) {
112-
result.push(key_value);
109+
if !environ.is_null() {
110+
while !(*environ).is_null() {
111+
if let Some(key_value) = parse(CStr::from_ptr(*environ).to_bytes()) {
112+
result.push(key_value);
113+
}
114+
environ = environ.add(1);
113115
}
114-
environ = environ.offset(1);
115116
}
116117
return Env { iter: result.into_iter(), _dont_send_or_sync_me: PhantomData };
117118
}

src/libstd/sys/windows/os.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub fn error_string(mut errnum: i32) -> String {
4343
];
4444
module = c::GetModuleHandleW(NTDLL_DLL.as_ptr());
4545

46-
if module != ptr::null_mut() {
46+
if !module.is_null() {
4747
errnum ^= c::FACILITY_NT_BIT as i32;
4848
flags = c::FORMAT_MESSAGE_FROM_HMODULE;
4949
}

0 commit comments

Comments
 (0)