From 2571cf272a9785ee119b49bd1b22971ddcbfdedc Mon Sep 17 00:00:00 2001 From: Andy Bailey Date: Thu, 5 Oct 2023 10:46:39 -0500 Subject: [PATCH] Changed str_to_u32 to remove unsafe code. Need to verify Native Endian works on all platforms --- Cargo.toml | 13 +++++++++++++ src/mac_avf/video_output_settings.rs | 7 +------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 221ef68..8076fcb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,3 +41,16 @@ winit = "0.27.5" [dependencies] ffimage = "0.9.0" ffimage_yuv = "0.9.0" +log = "0.4.20" + +[profile.test] +opt-level=3 +#debug = false +#split-debuginfo = '...' # Platform-specific. +#debug-assertions = false +#overflow-checks = false +#lto = false +#panic = 'unwind' +#incremental = false +#codegen-units = 16 +#rpath = false diff --git a/src/mac_avf/video_output_settings.rs b/src/mac_avf/video_output_settings.rs index 0f4f975..63b9cb4 100644 --- a/src/mac_avf/video_output_settings.rs +++ b/src/mac_avf/video_output_settings.rs @@ -20,12 +20,7 @@ pub fn video_settings_rgb24() -> Id> { fn str_to_u32(string: &str) -> u32 { assert_eq!(4, string.len()); let bytes = string.as_bytes(); - let a = bytes[0]; - let b = bytes[1]; - let c = bytes[2]; - let d = bytes[3]; - - unsafe { std::mem::transmute::<[u8; 4], u32>([a, b, c, d]) } + u32::from_ne_bytes(bytes[0..4].try_into().unwrap()) } fn video_settings_with_pixel_format(