Skip to content

Commit

Permalink
src: fixed Tree Borrows violation due to mutation across the FFI in c…
Browse files Browse the repository at this point in the history
…rc4.
  • Loading branch information
icmccorm committed Feb 2, 2024
1 parent 7bf8f57 commit 5cc4a1f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ mod c_implementation {
extern "C" {
// C implementation described in the data sheet.
// This is test only to validate the rust implementation.
pub fn crc4(buffer: *const u16) -> u8;
pub fn crc4(buffer: *mut u16) -> u8;
}
}

Expand Down Expand Up @@ -189,7 +189,7 @@ mod tests {

#[test]
fn crc4() {
let c_input_buffer = [0xABCDu16, 1, 2, 3, 4, 5, 6, 7];
let mut c_input_buffer = [0xABCDu16, 1, 2, 3, 4, 5, 6, 7];

let mut input_buffer = c_input_buffer.clone();
// The C implementation zeroes the first 4bits of the buffer as that
Expand All @@ -201,7 +201,7 @@ mod tests {

let c_impl_crc: u8;
unsafe {
c_impl_crc = c_implementation::crc4(c_input_buffer.as_ptr());
c_impl_crc = c_implementation::crc4(c_input_buffer.as_mut_ptr());
}
// Also note that the c implementation requires a padding word that rust
// does not require.
Expand Down

0 comments on commit 5cc4a1f

Please sign in to comment.