Skip to content

Commit 587653a

Browse files
committed
GetUserProfileDirectoryW is now documented to always store the size
1 parent e88e854 commit 587653a

File tree

2 files changed

+3
-5
lines changed
  • library/std/src/sys/pal/windows
  • src/tools/miri/src/shims/windows

2 files changed

+3
-5
lines changed

library/std/src/sys/pal/windows/os.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,6 @@ fn home_dir_crt() -> Option<PathBuf> {
202202
|buf, mut sz| {
203203
// GetUserProfileDirectoryW does not quite use the usual protocol for
204204
// negotiating the buffer size, so we have to translate.
205-
// FIXME(#141254): We rely on the *undocumented* property that this function will
206-
// always set the size, not just on failure.
207205
match c::GetUserProfileDirectoryW(
208206
ptr::without_provenance_mut(CURRENT_PROCESS_TOKEN),
209207
buf,

src/tools/miri/src/shims/windows/env.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,16 +230,16 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
230230
interp_ok(match directories::UserDirs::new() {
231231
Some(dirs) => {
232232
let home = dirs.home_dir();
233-
let size_avail = if this.ptr_is_null(size.ptr())? {
233+
let size_avail = if this.ptr_is_null(buf)? {
234234
0 // if the buf pointer is null, we can't write to it; `size` will be updated to the required length
235235
} else {
236236
this.read_scalar(&size)?.to_u32()?
237237
};
238238
// Of course we cannot use `windows_check_buffer_size` here since this uses
239239
// a different method for dealing with a too-small buffer than the other functions...
240240
let (success, len) = this.write_path_to_wide_str(home, buf, size_avail.into())?;
241-
// The Windows docs just say that this is written on failure, but std relies on it
242-
// always being written. Also see <https://github.com/rust-lang/rust/issues/141254>.
241+
// As per <https://github.com/MicrosoftDocs/sdk-api/pull/1810>, the size is always
242+
// written, not just on failure.
243243
this.write_scalar(Scalar::from_u32(len.try_into().unwrap()), &size)?;
244244
if success {
245245
Scalar::from_i32(1) // return TRUE

0 commit comments

Comments
 (0)