Skip to content

Commit

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

The function signature of log_debug_message() was modified to take into account an error occurring. PR is a breaking change due to this.

Fixed potential panic when unwrapping parse() for MultiAddr.

Fixed missing documentation for init_logging().

Motivation and Context
---
Removal of calls to unwrap() and bug fixes.

How Has This Been Tested?
---
cargo test --all
  • Loading branch information
StriderDM committed Nov 19, 2021
1 parent 8e271d7 commit 476c512
Show file tree
Hide file tree
Showing 3 changed files with 482 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(ref p) => Self {
code: 9,
message: format!("Pointer error on {}:{:?}", p, v),
},
}
}
}
Expand Down
Loading

0 comments on commit 476c512

Please sign in to comment.