Skip to content

Commit c51fc15

Browse files
committed
remove unsafe
1 parent 0fc8f7f commit c51fc15

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

src/lib.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -411,14 +411,8 @@ pub fn hash(salt: &[u8], rom: &Rom, nb_loops: u32, nb_instrs: u32) -> [u8; 64] {
411411
}
412412

413413
pub fn hash_structure_good(hash: &[u8], difficulty_mask: u32) -> bool {
414-
let u32_ptr = hash.as_ptr() as *const u32;
415-
unsafe {
416-
let value = u32_ptr.read_unaligned().to_be();
417-
if (value | difficulty_mask) == difficulty_mask {
418-
return true
419-
}
420-
}
421-
false
414+
let value = u32::from_be_bytes(hash[..4].try_into().unwrap());
415+
(value | difficulty_mask) == difficulty_mask
422416
}
423417

424418
// --------------------------------------------------------------------------
@@ -468,11 +462,8 @@ pub fn build_preimage(
468462
}
469463

470464
fn update_preimage_nonce(preimage_string: &mut String, nonce: u64) {
471-
let bytes = unsafe {
472-
preimage_string.as_bytes_mut()
473-
};
474465
let nonce_str = format!("{:016x}", nonce);
475-
bytes[..16].copy_from_slice(nonce_str.as_bytes());
466+
preimage_string.replace_range(0..16, &nonce_str);
476467
}
477468

478469
// The worker thread function

0 commit comments

Comments
 (0)