From f661d5d1c099e78ff26f0fb4754d40302bd00e19 Mon Sep 17 00:00:00 2001 From: Jeremy Soller <jackpot51@gmail.com> Date: Sat, 15 Sep 2018 11:14:51 -0600 Subject: [PATCH] Fix use of uninitialized memory --- src/header/stdio/helpers.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/header/stdio/helpers.rs b/src/header/stdio/helpers.rs index 7f5bcad83..b7dc4c06d 100644 --- a/src/header/stdio/helpers.rs +++ b/src/header/stdio/helpers.rs @@ -1,4 +1,4 @@ -use core::mem; +use core::{mem, ptr}; use core::sync::atomic::AtomicBool; use header::errno; @@ -67,14 +67,16 @@ pub unsafe fn _fdopen(fd: c_int, mode: *const c_char) -> Option<*mut FILE> { if f.is_null() { None } else { - (*f).flags = flags; - (*f).read = None; - (*f).write = None; - (*f).fd = fd; - (*f).buf = vec![0u8; BUFSIZ + UNGET]; - (*f).buf_char = -1; - (*f).unget = UNGET; - (*f).lock = AtomicBool::new(false); + ptr::write(f, FILE { + flags: flags, + read: None, + write: None, + fd: fd, + buf: vec![0u8; BUFSIZ + UNGET], + buf_char: -1, + unget: UNGET, + lock: AtomicBool::new(false) + }); Some(f) } } -- GitLab