From e968c27be56e68f8992d35e174ceace4c212efcb Mon Sep 17 00:00:00 2001 From: Electric <76964455+313ctric@users.noreply.github.com> Date: Tue, 19 Dec 2023 17:32:58 +0000 Subject: [PATCH] Actually fix things --- src/lib.rs | 5 ++--- src/util.rs | 7 ------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 02e7c61..8532825 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -240,11 +240,10 @@ async fn handler( let _status = socket.read_u32().await?; let mut bus_id = [0u8; 32]; socket.read_exact(&mut bus_id).await?; + let bus_id_compare = &bus_id[..bus_id.iter().position(|&x| x == 0).unwrap_or(bus_id.len())]; current_import_device = None; for device in &server.devices { - let mut expected = device.bus_id.as_bytes().to_vec(); - expected.resize(32, 0); - if str_eq(&expected, &bus_id) { + if bus_id_compare == device.bus_id.as_bytes() { current_import_device = Some(device); info!("Found device {:?}", device.path); break; diff --git a/src/util.rs b/src/util.rs index 439c4a3..d0d579b 100644 --- a/src/util.rs +++ b/src/util.rs @@ -20,13 +20,6 @@ pub fn verify_descriptor(desc: &[u8]) { assert_eq!(offset, desc.len()); } -pub fn str_eq(a: &[u8], b: &[u8]) -> bool { - let a_idx = a.iter().position(|&x| x == 0).unwrap_or(a.len()); - let b_idx = b.iter().position(|&x| x == 0).unwrap_or(b.len()); - - a[..a_idx] == b[..b_idx] -} - #[cfg(test)] pub(crate) mod tests { use std::{