Skip to content

Commit 085c4c9

Browse files
Revert "Win: rename: Use offset_of! in struct size calculation"
This reverts commit bfadeeb.
1 parent 74ec862 commit 085c4c9

File tree

1 file changed

+4
-7
lines changed
  • library/std/src/sys/pal/windows

1 file changed

+4
-7
lines changed

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,13 +1258,8 @@ pub fn rename(old: &Path, new: &Path) -> io::Result<()> {
12581258

12591259
let new_len_without_nul_in_bytes = (new.len() - 1).try_into().unwrap();
12601260

1261-
// The last field of FILE_RENAME_INFO, the file name, is unsized,
1262-
// and FILE_RENAME_INFO has two padding bytes.
1263-
// Therefore we need to make sure to not allocate less than
1264-
// size_of::<c::FILE_RENAME_INFO>() bytes, which would be the case with
1265-
// 0 or 1 character paths + a null byte.
1266-
let struct_size = mem::size_of::<c::FILE_RENAME_INFO>()
1267-
.max(mem::offset_of!(c::FILE_RENAME_INFO, FileName) + new.len() * mem::size_of::<u16>());
1261+
let struct_size = mem::size_of::<c::FILE_RENAME_INFO>() - mem::size_of::<u16>()
1262+
+ new.len() * mem::size_of::<u16>();
12681263

12691264
let struct_size: u32 = struct_size.try_into().unwrap();
12701265

@@ -1335,6 +1330,8 @@ pub fn rename(old: &Path, new: &Path) -> io::Result<()> {
13351330
}
13361331
.unwrap_or_else(|| create_file(0, 0))?;
13371332

1333+
// The last field of FILE_RENAME_INFO, the file name, is unsized.
1334+
// Therefore we need to subtract the size of one wide char.
13381335
let layout = core::alloc::Layout::from_size_align(
13391336
struct_size as _,
13401337
mem::align_of::<c::FILE_RENAME_INFO>(),

0 commit comments

Comments
 (0)