Skip to content

Commit

Permalink
Mark AccComplex::from_ptr as unsafe
Browse files Browse the repository at this point in the history
Fixes #84

Mark the `AccComplex::from_ptr` function as `unsafe`.

* Add a safety comment to the `AccComplex::from_ptr` function explaining the potential risk of dereferencing a raw pointer.
* Update the function signature to indicate it is unsafe.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/Ragarnoy/a121-rs/issues/84?shareId=XXXX-XXXX-XXXX-XXXX).
  • Loading branch information
Ragarnoy committed Oct 23, 2024
1 parent 1d54532 commit f11962e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ impl AccComplex {
Self::default()
}

pub fn from_ptr(ptr: *const acc_int16_complex_t) -> Self {
/// Creates a new `AccComplex` instance from a raw pointer.
///
/// # Safety
/// This function is unsafe because it dereferences a raw pointer.
/// The caller must ensure that the pointer is valid and points to a properly initialized `acc_int16_complex_t` struct.
pub unsafe fn from_ptr(ptr: *const acc_int16_complex_t) -> Self {
Self {
inner: unsafe { *ptr },
inner: *ptr,
}
}

Expand Down

0 comments on commit f11962e

Please sign in to comment.