From c1e2659ff203cfa873ae54eed1c8a553d711d0de Mon Sep 17 00:00:00 2001 From: Bogdan Mart Date: Thu, 28 Oct 2021 01:50:31 +0300 Subject: [PATCH] Fix bug -- high word of size for compressed files on windows was ignored --- Cargo.toml | 2 +- src/ffi.rs | 12 +++--------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1978fa5..ace813c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dirstat-rs" -version = "0.3.3" +version = "0.3.4" authors = ["scullionw "] edition = "2018" license = "MIT" diff --git a/src/ffi.rs b/src/ffi.rs index c036a33..8334819 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -5,7 +5,6 @@ use std::io; use std::iter::once; use std::os::windows::ffi::OsStrExt; use std::path::Path; -use std::ptr::null_mut; use winapi::shared::winerror::NO_ERROR; use winapi::um::errhandlingapi::GetLastError; use winapi::um::fileapi::GetCompressedFileSizeW; @@ -13,10 +12,10 @@ use winapi::um::fileapi::INVALID_FILE_SIZE; pub fn compressed_size(path: &Path) -> Result> { let wide: Vec = path.as_os_str().encode_wide().chain(once(0)).collect(); - let high: *mut u32 = null_mut(); + let mut high: u32 = 0; // TODO: Deal with max path size - let low = unsafe { GetCompressedFileSizeW(wide.as_ptr(), high) }; + let low = unsafe { GetCompressedFileSizeW(wide.as_ptr(), &mut high) }; if low == INVALID_FILE_SIZE { let err = get_last_error(); @@ -25,12 +24,7 @@ pub fn compressed_size(path: &Path) -> Result> { } } - if high.is_null() { - Ok(u64::from(low)) - } else { - let high = unsafe { *high }; - Ok(u64::from(high) << 32 | u64::from(low)) - } + Ok(u64::from(high) << 32 | u64::from(low)) } fn get_last_error() -> u32 {