Skip to content

Commit

Permalink
cleanup: Get null pointers through core rather than casting 0
Browse files Browse the repository at this point in the history
  • Loading branch information
chrysn committed Aug 28, 2024
1 parent 1160764 commit a4b15ce
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/gnrc/ipv6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ impl<M: Mode> Pktsnip<M> {
// unsafe: C API, and requirement on a Pktsnip that typed snips follow that type's
// conventions
let ptr = unsafe { riot_sys::gnrc_ipv6_get_header(self.ptr) };
if ptr == 0 as _ {
if ptr.is_null() {
None
} else {
// unsafe: Header is a transparent wrapper around the actual ipv6_hdr_t, and the
Expand Down
2 changes: 1 addition & 1 deletion src/gnrc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Netif {

#[doc(alias = "gnrc_netif_get_by_pid")]
pub fn by_pid(pid: KernelPID) -> Option<Self> {
const NULL: *mut riot_sys::gnrc_netif_t = 0 as _;
const NULL: *mut riot_sys::gnrc_netif_t = core::ptr::null_mut();
// Not using as_ref: We can't guarantee that even for the short period between we're making
// it into a reference and casting it back to a pointer again, it is not used by anyone
// else
Expand Down
2 changes: 1 addition & 1 deletion src/gnrc_pktbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl<'a> Pktsnip<Shared> {
// unsafe: The C functions justify the new type
unsafe {
let new = riot_sys::gnrc_pktbuf_start_write(self.to_ptr());
if new == 0 as _ {
if new.is_null() {
Err(NotEnoughSpace)
} else {
Ok(Pktsnip::<Writable>::from_ptr(new))
Expand Down
2 changes: 1 addition & 1 deletion src/saul/registration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ where
) -> Self {
Registration {
reg: riot_sys::saul_reg_t {
next: 0 as _,
next: core::ptr::null_mut(),
dev: device as *const _ as *mut _,
name: name.map(|n| n.as_ptr() as _).unwrap_or(core::ptr::null()),
driver: &driver.driver as *const _,
Expand Down
2 changes: 1 addition & 1 deletion src/ztimer/periodic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl<H: Handler, const HZ: u32> Timer<H, HZ> {
clock.0,
timer.as_mut_ptr(),
Some(Self::callback),
0 as _,
core::ptr::null_mut(),
ticks.0,
);
timer.assume_init()
Expand Down

0 comments on commit a4b15ce

Please sign in to comment.