Skip to content

Commit 9e03b41

Browse files
committed
Migrate readdir_r from pointers to places
1 parent 9fcc8a2 commit 9e03b41

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/shims/fs.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -902,13 +902,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
902902
// pub d_name: [c_char; 256],
903903
// }
904904

905-
let entry_ptr = this.force_ptr(this.read_scalar(entry_op)?.not_undef()?)?;
906-
let dirent64_layout = this.libc_ty_layout("dirent64")?;
907-
let name_offset = dirent64_layout.details.fields.offset(4);
908-
let name_ptr = entry_ptr.offset(name_offset, this)?;
905+
let entry_place = this.deref_operand(entry_op)?;
906+
let name_place = this.mplace_field(entry_place, 4)?;
909907

910908
let file_name = dir_entry.file_name();
911-
let name_fits = this.write_os_str_to_c_str(&file_name, Scalar::Ptr(name_ptr), 256)?;
909+
let name_fits = this.write_os_str_to_c_str(&file_name, name_place.ptr, name_place.layout.size.bytes())?;
912910
if !name_fits {
913911
throw_unsup_format!("A directory entry had a name too large to fit in libc::dirent64");
914912
}
@@ -988,13 +986,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
988986
// pub d_name: [c_char; 1024],
989987
// }
990988

991-
let entry_ptr = this.force_ptr(this.read_scalar(entry_op)?.not_undef()?)?;
992-
let dirent_layout = this.libc_ty_layout("dirent")?;
993-
let name_offset = dirent_layout.details.fields.offset(5);
994-
let name_ptr = entry_ptr.offset(name_offset, this)?;
989+
let entry_place = this.deref_operand(entry_op)?;
990+
let name_place = this.mplace_field(entry_place, 5)?;
995991

996992
let file_name = dir_entry.file_name();
997-
let name_fits = this.write_os_str_to_c_str(&file_name, Scalar::Ptr(name_ptr), 1024)?;
993+
let name_fits = this.write_os_str_to_c_str(&file_name, name_place.ptr, name_place.layout.size.bytes())?;
998994
if !name_fits {
999995
throw_unsup_format!("A directory entry had a name too large to fit in libc::dirent");
1000996
}

0 commit comments

Comments
 (0)