diff --git a/ragnaroek/src/comms/net_bind.rs b/ragnaroek/src/comms/net_bind.rs index 94512ee..f9ddeaf 100644 --- a/ragnaroek/src/comms/net_bind.rs +++ b/ragnaroek/src/comms/net_bind.rs @@ -50,8 +50,7 @@ impl Communicator for Connection { } fn recv_exact(&mut self, how_much: usize) -> IOResult> { - let mut buf = vec![]; - buf.resize(how_much, 0); + let mut buf = vec![0; how_much]; self.s.read_exact(&mut buf)?; log::trace!(target: "NET", "Recv exact: {}", format_data_buf(&buf)); diff --git a/ragnaroek/src/comms/net_connect.rs b/ragnaroek/src/comms/net_connect.rs index 81363bd..eb5e0ce 100644 --- a/ragnaroek/src/comms/net_connect.rs +++ b/ragnaroek/src/comms/net_connect.rs @@ -29,8 +29,7 @@ impl Communicator for Connection { } fn recv_exact(&mut self, how_much: usize) -> IOResult> { - let mut buf = vec![]; - buf.resize(how_much, 0); + let mut buf = vec![0; how_much]; self.s.read_exact(&mut buf)?; log::trace!(target: "NET", "Recv: {}",format_data_buf(&buf)); diff --git a/ragnaroek/src/comms/usb.rs b/ragnaroek/src/comms/usb.rs index cc07f72..9786235 100644 --- a/ragnaroek/src/comms/usb.rs +++ b/ragnaroek/src/comms/usb.rs @@ -108,8 +108,7 @@ impl Communicator for Connection { } fn recv_exact(&mut self, how_much: usize) -> IOResult> { - let mut buf = vec![]; - buf.resize(how_much, 0); + let mut buf = vec![0; how_much]; match self .handle .read_bulk(self.recv_endpoint, &mut buf, self.timeout) @@ -124,9 +123,8 @@ impl Communicator for Connection { } fn recv(&mut self) -> IOResult> { - let mut buf = vec![]; // TODO: Figure out max size properly - buf.resize(1024 * 1024, 0); + let mut buf = vec![0; 1024 * 1024]; match self .handle .read_bulk(self.recv_endpoint, &mut buf, Duration::from_millis(1)) diff --git a/ragnaroek/src/download_protocol/download_pit.rs b/ragnaroek/src/download_protocol/download_pit.rs index 2fd58fa..b4c509f 100644 --- a/ragnaroek/src/download_protocol/download_pit.rs +++ b/ragnaroek/src/download_protocol/download_pit.rs @@ -20,8 +20,7 @@ pub(crate) fn download_pit(c: &mut Box, p: SessionParams) -> R let total_len: usize = total_len .try_into() .expect("Not trying to run this on a 16-bit platform, are you?"); - let mut data: Vec = Vec::new(); - data.reserve(total_len); + let mut data: Vec = Vec::with_capacity(total_len); let mut chunk_idx: usize = 0; while data.len() < total_len { diff --git a/ragnaroek/src/download_protocol/types/cmd_packet.rs b/ragnaroek/src/download_protocol/types/cmd_packet.rs index e49cea9..a7bf038 100644 --- a/ragnaroek/src/download_protocol/types/cmd_packet.rs +++ b/ragnaroek/src/download_protocol/types/cmd_packet.rs @@ -122,8 +122,7 @@ impl OdinCmdPacket { /// Send the constructed packet in the proper format over the given `Communicator`. pub(crate) fn send(&self, comm: &mut Box) -> Result<()> { - let mut buf: Vec = Vec::new(); - buf.reserve(CMD_PACKET_LEN); + let mut buf: Vec = Vec::with_capacity(CMD_PACKET_LEN); let cmd_int: OdinInt = self.cmd.into(); buf.extend_from_slice(&cmd_int.to_wire()); diff --git a/ragnaroek/src/upload_protocol/end_session.rs b/ragnaroek/src/upload_protocol/end_session.rs index b9f9aab..feb908a 100644 --- a/ragnaroek/src/upload_protocol/end_session.rs +++ b/ragnaroek/src/upload_protocol/end_session.rs @@ -1,7 +1,7 @@ use crate::Communicator; use crate::Result; -const POSTAMBLE: &[u8] = &[b'P', b'o', b'S', b't', b'A', b'm', b'B', b'l', b'E', b'\0']; +const POSTAMBLE: &[u8] = b"PoStAmBlE\0"; /// End a session with the target. /// Must be called before disconnecting from the device. diff --git a/ragnaroek/src/upload_protocol/handshake.rs b/ragnaroek/src/upload_protocol/handshake.rs index 5e14b25..e5a9a97 100644 --- a/ragnaroek/src/upload_protocol/handshake.rs +++ b/ragnaroek/src/upload_protocol/handshake.rs @@ -7,10 +7,8 @@ use crate::Result; use super::UploadProtocolError; -const PREAMBLE: &[u8] = &[b'P', b'r', b'E', b'a', b'M', b'b', b'L', b'e', b'\0']; -const ACKNOWLEDGMENT: &[u8] = &[ - b'A', b'c', b'K', b'n', b'O', b'w', b'L', b'e', b'D', b'g', b'M', b'e', b'N', b't', b'\0', -]; +const PREAMBLE: &[u8] = b"PrEaMbLe\0"; +const ACKNOWLEDGMENT: &[u8] = b"AcKnOwLeDgMeNt\0"; /// Handshake with the target. /// This must be called before performing any other upload mode operations. diff --git a/ragnaroek/src/upload_protocol/mod.rs b/ragnaroek/src/upload_protocol/mod.rs index ffa8573..b606b7c 100644 --- a/ragnaroek/src/upload_protocol/mod.rs +++ b/ragnaroek/src/upload_protocol/mod.rs @@ -30,8 +30,7 @@ pub enum Bitness { /// Sends the given packet to the target. /// Adds padding if needed. fn send_packet(c: &mut Box, data: &[u8]) -> Result<()> { - let mut padded: Vec = Vec::new(); - padded.resize(PACKET_LEN, 0); + let mut padded: Vec = vec![0; PACKET_LEN]; for (i, byte) in data.iter().enumerate() { padded[i] = *byte; } diff --git a/ragnaroek/src/upload_protocol/probe.rs b/ragnaroek/src/upload_protocol/probe.rs index 8f5b92e..c96f603 100644 --- a/ragnaroek/src/upload_protocol/probe.rs +++ b/ragnaroek/src/upload_protocol/probe.rs @@ -7,7 +7,7 @@ use either::*; const DEVICE_NAME_LEN: usize = 16; const PARTITION_NAME_LEN: usize = 12; -const PROBE: &[u8] = &[b'P', b'r', b'O', b'b', b'E', b'\0']; +const PROBE: &[u8] = b"PrObE\0"; /// Data structure holding information the target returns about itself. #[derive(Debug, Clone)] @@ -49,7 +49,6 @@ impl ProbeTable { let (device_name, data) = read_string_and_advance(data, DEVICE_NAME_LEN); // Keep reading an unknown amount of entries - let data = data; let entries = match bitness { Bitness::ThirtyTwo => { let (entries_32, _) = read_probe_entries_32_and_advance(data); diff --git a/ragnaroek/src/upload_protocol/transfer.rs b/ragnaroek/src/upload_protocol/transfer.rs index 78cd4fc..0ef038b 100644 --- a/ragnaroek/src/upload_protocol/transfer.rs +++ b/ragnaroek/src/upload_protocol/transfer.rs @@ -2,7 +2,7 @@ use super::send_packet; use super::Bitness; use crate::{Communicator, Result}; -const DATAXFER: &[u8] = &[b'D', b'a', b'T', b'a', b'X', b'f', b'E', b'r', b'\0']; +const DATAXFER: &[u8] = b"DaTaXfEr\0"; const TRANSFER_MAX_SIZE: usize = 0x80000; // 512KiB /// Dump target memory in upload mode.