Skip to content

Commit 197360c

Browse files
committed
Rename write/read os string functions
1 parent 7218df8 commit 197360c

File tree

3 files changed

+6
-10
lines changed

3 files changed

+6
-10
lines changed

src/helpers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,12 +350,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
350350
Ok(())
351351
}
352352

353-
fn read_os_string(&mut self, scalar: Scalar<Tag>) -> InterpResult<'tcx, OsString> {
353+
fn read_os_string_from_c_string(&mut self, scalar: Scalar<Tag>) -> InterpResult<'tcx, OsString> {
354354
let bytes = self.eval_context_mut().memory.read_c_str(scalar)?;
355355
Ok(bytes_to_os_str(bytes)?.into())
356356
}
357357

358-
fn write_os_str(&mut self, os_str: &OsStr, ptr: Pointer<Tag>, size: u64) -> InterpResult<'tcx> {
358+
fn write_os_str_to_c_string(&mut self, os_str: &OsStr, ptr: Pointer<Tag>, size: u64) -> InterpResult<'tcx> {
359359
let bytes = os_str_to_bytes(os_str)?;
360360
// If `size` is smaller or equal than `bytes.len()`, writing `bytes` plus the required null
361361
// terminator to memory using the `ptr` pointer would cause an overflow.

src/shims/env.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
130130
// If we cannot get the current directory, we return null
131131
match env::current_dir() {
132132
Ok(cwd) => {
133-
if this.write_os_str(&OsString::from(cwd), buf, size).is_ok() {
133+
if this.write_os_str_to_c_string(&OsString::from(cwd), buf, size).is_ok() {
134134
return Ok(Scalar::Ptr(buf));
135135
}
136136
let erange = this.eval_libc("ERANGE")?;
@@ -146,7 +146,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
146146

147147
this.check_no_isolation("chdir")?;
148148

149-
let path = this.read_os_string(this.read_scalar(path_op)?.not_undef()?)?;
149+
let path = this.read_os_string_from_c_string(this.read_scalar(path_op)?.not_undef()?)?;
150150

151151
match env::set_current_dir(path) {
152152
Ok(()) => Ok(0),

src/shims/fs.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
9494
throw_unsup_format!("unsupported flags {:#x}", flag & !mirror);
9595
}
9696

97-
let path: std::path::PathBuf = this.read_os_string(this.read_scalar(path_op)?.not_undef()?)?.into();
97+
let path: std::path::PathBuf = this.read_os_string_from_c_string(this.read_scalar(path_op)?.not_undef()?)?.into();
9898

9999
let fd = options.open(path).map(|file| {
100100
let mut fh = &mut this.machine.file_handler;
@@ -214,11 +214,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
214214

215215
this.check_no_isolation("unlink")?;
216216

217-
let path_bytes = this
218-
.memory
219-
.read_c_str(this.read_scalar(path_op)?.not_undef()?)?;
220-
let path = std::str::from_utf8(path_bytes)
221-
.map_err(|_| err_unsup_format!("{:?} is not a valid utf-8 string", path_bytes))?;
217+
let path = this.read_os_string_from_c_string(this.read_scalar(path_op)?.not_undef()?)?;
222218

223219
let result = remove_file(path).map(|_| 0);
224220

0 commit comments

Comments
 (0)