Skip to content

Commit

Permalink
Add error reporting for null pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
lmoe committed Jul 14, 2023
1 parent 33e54b6 commit 4938889
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions bindings/native/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use iota_sdk_bindings_core::{
ClientMethod,
};

use crate::error::{set_last_error, Result};
use crate::error::{set_last_error, Result, Error};

pub struct Client {
pub client: RustClient,
Expand Down Expand Up @@ -52,7 +52,7 @@ unsafe fn internal_destroy_client(client_ptr: *mut Client) -> Result<()> {

if client_ptr.is_null() {
log::error!("[Rust] Client pointer was null!");
return Ok(());
return Err(Error::from("pointer is null"));
}

let _ = Box::from_raw(client_ptr);
Expand Down
4 changes: 2 additions & 2 deletions bindings/native/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ pub(crate) fn block_on<C: futures::Future>(cb: C) -> C::Output {

unsafe fn internal_destroy_string(ptr: *mut c_char) -> Result<()> {
if ptr.is_null() {
return Ok(());
log::error!("[Rust] String pointer was null!");
return Err(Error::from("pointer is null"));
}


let mut str = CString::from_raw(ptr);
str.zeroize();

Expand Down
4 changes: 2 additions & 2 deletions bindings/native/src/secret_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use iota_sdk_bindings_core::{
};
use tokio::sync::RwLock;

use crate::error::{set_last_error, Result};
use crate::error::{set_last_error, Result, Error};

pub struct SecretManager {
pub secret_manager: Arc<RwLock<RustSecretManager>>,
Expand Down Expand Up @@ -51,7 +51,7 @@ unsafe fn internal_destroy_secret_manager(secret_manager_ptr: *mut SecretManager

if secret_manager_ptr.is_null() {
log::error!("[Rust] Secret Manager pointer was null!");
return Ok(());
return Err(Error::from("pointer is null"));
}

let _ = Box::from_raw(secret_manager_ptr);
Expand Down

0 comments on commit 4938889

Please sign in to comment.