Skip to content

Commit

Permalink
refactor!: clean up unwraps in wallet_ffi
Browse files Browse the repository at this point in the history
Remove unwrap() in functions of wallet_ffi, code is considered best-effort to try prevent a panic since the nature of handling invalid pointers or invalidly converted pointers passed in results in undefined behaviour.

Modified function signature of log_debug_message() to take into account an error occurring.

Fixed potential panic when unwrapping parse() for MultiAddr.

Fixed missing documentation for init_logging()

cargo-fmt
  • Loading branch information
StriderDM committed Nov 17, 2021
1 parent 337bc6f commit 8dea2ab
Show file tree
Hide file tree
Showing 3 changed files with 479 additions and 100 deletions.
6 changes: 6 additions & 0 deletions base_layer/wallet_ffi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ const LOG_TARGET: &str = "wallet_ffi::error";
pub enum InterfaceError {
#[error("An error has occurred due to one of the parameters being null: `{0}`")]
NullError(String),
#[error("An invalid pointer was passed into the function")]
PointerError(String),
#[error("An error has occurred when checking the length of the allocated object")]
AllocationError,
#[error("An error because the supplied position was out of range")]
Expand Down Expand Up @@ -101,6 +103,10 @@ impl From<InterfaceError> for LibWalletError {
code: 8,
message: "Balance Unavailable".to_string(),
},
InterfaceError::PointerError(_) => Self {
code: 9,
message: format!("{:?}", v),
},
}
}
}
Expand Down
Loading

0 comments on commit 8dea2ab

Please sign in to comment.