From 85941c72497e69653b847744a447ae51b433d4ba Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 18 Oct 2019 09:30:12 -0500 Subject: [PATCH] Rename write/read os string functions --- src/helpers.rs | 4 ++-- src/shims/env.rs | 4 ++-- src/shims/fs.rs | 8 ++------ 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/helpers.rs b/src/helpers.rs index 32edb107f36..454f7d2c2f8 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -346,12 +346,12 @@ fn check_no_isolation(&mut self, name: &str) -> InterpResult<'tcx> { Ok(()) } - fn read_os_string(&mut self, scalar: Scalar) -> InterpResult<'tcx, OsString> { + fn read_os_string_from_c_string(&mut self, scalar: Scalar) -> InterpResult<'tcx, OsString> { let bytes = self.eval_context_mut().memory.read_c_str(scalar)?; Ok(bytes_to_os_str(bytes)?.into()) } - fn write_os_str(&mut self, os_str: &OsStr, ptr: Pointer, size: u64) -> InterpResult<'tcx> { + fn write_os_str_to_c_string(&mut self, os_str: &OsStr, ptr: Pointer, size: u64) -> InterpResult<'tcx> { let bytes = os_str_to_bytes(os_str)?; // If `size` is smaller or equal than `bytes.len()`, writing `bytes` plus the required null // terminator to memory using the `ptr` pointer would cause an overflow. diff --git a/src/shims/env.rs b/src/shims/env.rs index b2e0709557d..7e2df4f985d 100644 --- a/src/shims/env.rs +++ b/src/shims/env.rs @@ -128,7 +128,7 @@ fn getcwd( // If we cannot get the current directory, we return null match env::current_dir() { Ok(cwd) => { - if this.write_os_str(&OsString::from(cwd), buf, size).is_ok() { + if this.write_os_str_to_c_string(&OsString::from(cwd), buf, size).is_ok() { return Ok(Scalar::Ptr(buf)); } let erange = this.eval_libc("ERANGE")?; @@ -144,7 +144,7 @@ fn chdir(&mut self, path_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> { this.check_no_isolation("chdir")?; - let path = this.read_os_string(this.read_scalar(path_op)?.not_undef()?)?; + let path = this.read_os_string_from_c_string(this.read_scalar(path_op)?.not_undef()?)?; match env::set_current_dir(path) { Ok(()) => Ok(0), diff --git a/src/shims/fs.rs b/src/shims/fs.rs index d4f9fde24e1..7cc574f05f1 100644 --- a/src/shims/fs.rs +++ b/src/shims/fs.rs @@ -94,7 +94,7 @@ fn open( throw_unsup_format!("unsupported flags {:#x}", flag & !mirror); } - let path: std::path::PathBuf = this.read_os_string(this.read_scalar(path_op)?.not_undef()?)?.into(); + let path: std::path::PathBuf = this.read_os_string_from_c_string(this.read_scalar(path_op)?.not_undef()?)?.into(); let fd = options.open(path).map(|file| { let mut fh = &mut this.machine.file_handler; @@ -210,11 +210,7 @@ fn unlink( &mut self, path_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> { this.check_no_isolation("unlink")?; - let path_bytes = this - .memory - .read_c_str(this.read_scalar(path_op)?.not_undef()?)?; - let path = std::str::from_utf8(path_bytes) - .map_err(|_| err_unsup_format!("{:?} is not a valid utf-8 string", path_bytes))?; + let path = this.read_os_string_from_c_string(this.read_scalar(path_op)?.not_undef()?)?; let result = remove_file(path).map(|_| 0); -- 2.44.0