mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-13 02:28:10 +00:00
Remove some allow(clippy::uninit_vec) (#2111)
Closes #1595. Leaving one instance of `allow(clippy::uninit_vec)` in `pipe_handle.rs` as it is more difficult to remove. (Maybe there's another crate we could use for pipes?) To satisfy clippy, instead of creating the vec and then resizing it straight away (exposing uninitialized data), write into the `spare_capacity_mut()` (which is `&mut [MaybeUninit<_>]`) and then resize it afterwards.
This commit is contained in:
@ -1,8 +1,6 @@
|
|||||||
// Copyright (c) Microsoft Corporation.
|
// Copyright (c) Microsoft Corporation.
|
||||||
// Licensed under the MIT License.
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
#![allow(clippy::uninit_vec)]
|
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
collections::{btree_map::Range, BTreeMap},
|
collections::{btree_map::Range, BTreeMap},
|
||||||
ops::RangeBounds,
|
ops::RangeBounds,
|
||||||
@ -269,10 +267,16 @@ impl BreakpointCollection {
|
|||||||
|
|
||||||
fn bulk_read_process_memory(&self, process_handle: HANDLE) -> Result<Vec<u8>> {
|
fn bulk_read_process_memory(&self, process_handle: HANDLE) -> Result<Vec<u8>> {
|
||||||
let mut buffer: Vec<u8> = Vec::with_capacity(self.bulk_region_size());
|
let mut buffer: Vec<u8> = Vec::with_capacity(self.bulk_region_size());
|
||||||
|
process::read_memory_array(
|
||||||
|
process_handle,
|
||||||
|
self.min_breakpoint_addr as _,
|
||||||
|
buffer.spare_capacity_mut(),
|
||||||
|
)?;
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
buffer.set_len(self.bulk_region_size());
|
buffer.set_len(self.bulk_region_size());
|
||||||
}
|
}
|
||||||
process::read_memory_array(process_handle, self.min_breakpoint_addr as _, &mut buffer)?;
|
|
||||||
Ok(buffer)
|
Ok(buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
// Copyright (c) Microsoft Corporation.
|
// Copyright (c) Microsoft Corporation.
|
||||||
// Licensed under the MIT License.
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
#![allow(clippy::uninit_vec)]
|
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
ffi::OsString,
|
ffi::OsString,
|
||||||
mem::{size_of, MaybeUninit},
|
mem::{size_of, MaybeUninit},
|
||||||
@ -112,10 +110,10 @@ pub fn read_narrow_string(
|
|||||||
len: usize,
|
len: usize,
|
||||||
) -> Result<String> {
|
) -> Result<String> {
|
||||||
let mut buf: Vec<u8> = Vec::with_capacity(len);
|
let mut buf: Vec<u8> = Vec::with_capacity(len);
|
||||||
|
read_memory_array(process_handle, remote_address, buf.spare_capacity_mut())?;
|
||||||
unsafe {
|
unsafe {
|
||||||
buf.set_len(len);
|
buf.set_len(len);
|
||||||
}
|
}
|
||||||
read_memory_array::<u8>(process_handle, remote_address, &mut buf[..])?;
|
|
||||||
Ok(String::from_utf8_lossy(&buf).into())
|
Ok(String::from_utf8_lossy(&buf).into())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,10 +123,10 @@ pub fn read_wide_string(
|
|||||||
len: usize,
|
len: usize,
|
||||||
) -> Result<OsString> {
|
) -> Result<OsString> {
|
||||||
let mut buf: Vec<u16> = Vec::with_capacity(len);
|
let mut buf: Vec<u16> = Vec::with_capacity(len);
|
||||||
|
read_memory_array(process_handle, remote_address, buf.spare_capacity_mut())?;
|
||||||
unsafe {
|
unsafe {
|
||||||
buf.set_len(len);
|
buf.set_len(len);
|
||||||
}
|
}
|
||||||
read_memory_array::<u16>(process_handle, remote_address, &mut buf[..])?;
|
|
||||||
Ok(OsString::from_wide(&buf))
|
Ok(OsString::from_wide(&buf))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user