Skip to content

Commit

Permalink
core: Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
casept committed Sep 8, 2024
1 parent 6f64843 commit 70899fb
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 22 deletions.
3 changes: 1 addition & 2 deletions ragnaroek/src/comms/net_bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ impl Communicator for Connection {
}

fn recv_exact(&mut self, how_much: usize) -> IOResult<Vec<u8>> {
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));
Expand Down
3 changes: 1 addition & 2 deletions ragnaroek/src/comms/net_connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ impl Communicator for Connection {
}

fn recv_exact(&mut self, how_much: usize) -> IOResult<Vec<u8>> {
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));
Expand Down
6 changes: 2 additions & 4 deletions ragnaroek/src/comms/usb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ impl Communicator for Connection {
}

fn recv_exact(&mut self, how_much: usize) -> IOResult<Vec<u8>> {
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)
Expand All @@ -124,9 +123,8 @@ impl Communicator for Connection {
}

fn recv(&mut self) -> IOResult<Vec<u8>> {
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))
Expand Down
3 changes: 1 addition & 2 deletions ragnaroek/src/download_protocol/download_pit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ pub(crate) fn download_pit(c: &mut Box<dyn Communicator>, 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<u8> = Vec::new();
data.reserve(total_len);
let mut data: Vec<u8> = Vec::with_capacity(total_len);

let mut chunk_idx: usize = 0;
while data.len() < total_len {
Expand Down
3 changes: 1 addition & 2 deletions ragnaroek/src/download_protocol/types/cmd_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn Communicator>) -> Result<()> {
let mut buf: Vec<u8> = Vec::new();
buf.reserve(CMD_PACKET_LEN);
let mut buf: Vec<u8> = Vec::with_capacity(CMD_PACKET_LEN);

let cmd_int: OdinInt = self.cmd.into();
buf.extend_from_slice(&cmd_int.to_wire());
Expand Down
2 changes: 1 addition & 1 deletion ragnaroek/src/upload_protocol/end_session.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
6 changes: 2 additions & 4 deletions ragnaroek/src/upload_protocol/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions ragnaroek/src/upload_protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ pub enum Bitness {
/// Sends the given packet to the target.
/// Adds padding if needed.
fn send_packet(c: &mut Box<dyn Communicator>, data: &[u8]) -> Result<()> {
let mut padded: Vec<u8> = Vec::new();
padded.resize(PACKET_LEN, 0);
let mut padded: Vec<u8> = vec![0; PACKET_LEN];
for (i, byte) in data.iter().enumerate() {
padded[i] = *byte;
}
Expand Down
3 changes: 1 addition & 2 deletions ragnaroek/src/upload_protocol/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion ragnaroek/src/upload_protocol/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 70899fb

Please sign in to comment.