Skip to content

Commit 85941c7

Browse files
committed
Rename write/read os string functions
1 parent 68fec4b commit 85941c7

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
@@ -346,12 +346,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
346346
Ok(())
347347
}
348348

349-
fn read_os_string(&mut self, scalar: Scalar<Tag>) -> InterpResult<'tcx, OsString> {
349+
fn read_os_string_from_c_string(&mut self, scalar: Scalar<Tag>) -> InterpResult<'tcx, OsString> {
350350
let bytes = self.eval_context_mut().memory.read_c_str(scalar)?;
351351
Ok(bytes_to_os_str(bytes)?.into())
352352
}
353353

354-
fn write_os_str(&mut self, os_str: &OsStr, ptr: Pointer<Tag>, size: u64) -> InterpResult<'tcx> {
354+
fn write_os_str_to_c_string(&mut self, os_str: &OsStr, ptr: Pointer<Tag>, size: u64) -> InterpResult<'tcx> {
355355
let bytes = os_str_to_bytes(os_str)?;
356356
// If `size` is smaller or equal than `bytes.len()`, writing `bytes` plus the required null
357357
// 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
@@ -128,7 +128,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
128128
// If we cannot get the current directory, we return null
129129
match env::current_dir() {
130130
Ok(cwd) => {
131-
if this.write_os_str(&OsString::from(cwd), buf, size).is_ok() {
131+
if this.write_os_str_to_c_string(&OsString::from(cwd), buf, size).is_ok() {
132132
return Ok(Scalar::Ptr(buf));
133133
}
134134
let erange = this.eval_libc("ERANGE")?;
@@ -144,7 +144,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
144144

145145
this.check_no_isolation("chdir")?;
146146

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

149149
match env::set_current_dir(path) {
150150
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;
@@ -210,11 +210,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
210210

211211
this.check_no_isolation("unlink")?;
212212

213-
let path_bytes = this
214-
.memory
215-
.read_c_str(this.read_scalar(path_op)?.not_undef()?)?;
216-
let path = std::str::from_utf8(path_bytes)
217-
.map_err(|_| err_unsup_format!("{:?} is not a valid utf-8 string", path_bytes))?;
213+
let path = this.read_os_string_from_c_string(this.read_scalar(path_op)?.not_undef()?)?;
218214

219215
let result = remove_file(path).map(|_| 0);
220216

0 commit comments

Comments
 (0)