Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use sys::statfs::statfs without unsafe #926

Closed
alesharik opened this issue Jul 9, 2018 · 1 comment
Closed

Can't use sys::statfs::statfs without unsafe #926

alesharik opened this issue Jul 9, 2018 · 1 comment

Comments

@alesharik
Copy link
Contributor

Current implementation of statfs requires mutable reference of result variable, but I can't pass it to statfs without initialization. For example this code

let mut statf: libc::statfs;
sys::statfs::statfs(Path::new(&String::from("/")), &mut statf).unwrap();

gives me this error:

error[E0381]: use of possibly uninitialized variable: `statf`
sys::statfs::statfs(Path::new(&String::from("/")), &mut statf).unwrap();
                                                        ^^^^^ use of possibly uninitialized `statf`

So I need to somehow initialize the variable:

let mut statf: libc::statfs = unsafe { mem::uninitialized() };
sys::statfs::statfs(Path::new(&String::from("/")), &mut statf).unwrap();

Maybe it will be better to return result with libc::statfs struct instead of empty result?

@Susurrus
Copy link
Contributor

Yes, that seems like the correct change. Additionally we should use a newtype wrapper around libc::statfs so we don't export libc types directly (this prevents libc breaking changes to become major-release breaking changes in nix).

The only open question here is whether reusing a statfs struct is ever necessary in practice. If so, we'd probably want two versions of each function, one returning the struct the other filling it in-place. I'd bet this functionality isn't necessary, but a look at production code would be useful here.

@alesharik Would you be willing to file a PR to fix this? It's unlikely to get fixed anytime soon if you aren't.

bors bot added a commit that referenced this issue Jun 20, 2019
928: Wrap libc::statfs r=asomers a=alesharik

Fix for [#926](#926)

Co-authored-by: alesharik <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants