Skip to content

Commit

Permalink
Merge pull request #6 from dwattttt/main
Browse files Browse the repository at this point in the history
Replace some mem::zeroed uses with idiomatic/safer approaches
  • Loading branch information
TimMisiak authored Nov 4, 2023
2 parents f893d9a + 38c6f39 commit 075cdd0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
8 changes: 5 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use windows_sys::{
Win32::System::{Diagnostics::Debug::*, Threading::*},
};

use std::ptr::null;
use std::{ptr::null, mem::MaybeUninit};

mod command;
mod eval;
Expand Down Expand Up @@ -265,7 +265,7 @@ fn main() {

let mut si: STARTUPINFOEXW = unsafe { std::mem::zeroed() };
si.StartupInfo.cb = std::mem::size_of::<STARTUPINFOEXW>() as u32;
let mut pi: PROCESS_INFORMATION = unsafe { std::mem::zeroed() };
let mut pi: MaybeUninit<PROCESS_INFORMATION> = MaybeUninit::uninit();
let ret = unsafe {
CreateProcessW(
null(),
Expand All @@ -277,14 +277,16 @@ fn main() {
null(),
null(),
&mut si.StartupInfo,
&mut pi,
pi.as_mut_ptr(),
)
};

if ret == 0 {
panic!("CreateProcessW failed");
}

let pi = unsafe { pi.assume_init() };

unsafe { CloseHandle(pi.hThread) };

// Later, we'll need to pass in a process handle.
Expand Down
7 changes: 1 addition & 6 deletions src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub enum ExportTarget {
Forwarder(String)
}

#[derive(Default)]
#[repr(C)]
pub struct PdbInfo {
pub signature: u32,
Expand All @@ -44,12 +45,6 @@ pub struct PdbInfo {
// Null terminated name goes after the end
}

impl ::core::default::Default for PdbInfo {
fn default() -> Self {
unsafe { ::core::mem::zeroed() }
}
}

impl ::core::marker::Copy for PdbInfo {}
impl ::core::clone::Clone for PdbInfo {
fn clone(&self) -> Self {
Expand Down

0 comments on commit 075cdd0

Please sign in to comment.