diff --git a/src/tools/miri/src/shims/env.rs b/src/tools/miri/src/shims/env.rs
index 402e2670888..298fefdb0f3 100644
--- a/src/tools/miri/src/shims/env.rs
+++ b/src/tools/miri/src/shims/env.rs
@@ -178,7 +178,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
&var,
buf_ptr,
buf_size.into(),
- /*truncate*/ false,
)?))
// This can in fact return 0. It is up to the caller to set last_error to 0
// beforehand and check it afterwards to exclude that case.
@@ -380,7 +379,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
// This can in fact return 0. It is up to the caller to set last_error to 0
// beforehand and check it afterwards to exclude that case.
return Ok(Scalar::from_u32(windows_check_buffer_size(
- this.write_path_to_wide_str(&cwd, buf, size, /*truncate*/ false)?,
+ this.write_path_to_wide_str(&cwd, buf, size)?,
)));
}
Err(e) => this.set_last_error_from_io_error(e.kind())?,
@@ -535,12 +534,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
};
// Of course we cannot use `windows_check_buffer_size` here since this uses
// a different method for dealing with a too-small buffer than the other functions...
- let (success, len) = this.write_path_to_wide_str(
- home,
- buf,
- size_avail.into(),
- /*truncate*/ false,
- )?;
+ let (success, len) = this.write_path_to_wide_str(home, buf, size_avail.into())?;
// The Windows docs just say that this is written on failure. But std
// seems to rely on it always being written.
this.write_scalar(Scalar::from_u32(len.try_into().unwrap()), &size)?;
diff --git a/src/tools/miri/src/shims/os_str.rs b/src/tools/miri/src/shims/os_str.rs
index 3e8c35d48ae..5fcea9ced69 100644
--- a/src/tools/miri/src/shims/os_str.rs
+++ b/src/tools/miri/src/shims/os_str.rs
@@ -72,11 +72,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
u16vec_to_osstring(u16_vec)
}
- /// Helper function to write an OsStr as a null-terminated sequence of bytes, which is what
- /// the Unix APIs usually handle. This function returns `Ok((false, length))` without trying
- /// to write if `size` is not large enough to fit the contents of `os_string` plus a null
- /// terminator. It returns `Ok((true, length))` if the writing process was successful. The
- /// string length returned does include the null terminator.
+ /// Helper function to write an OsStr as a null-terminated sequence of bytes, which is what the
+ /// Unix APIs usually handle. Returns `(success, full_len)`, where length includes the null
+ /// terminator. On failure, nothing is written.
fn write_os_str_to_c_str(
&mut self,
os_str: &OsStr,
@@ -87,19 +85,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
self.eval_context_mut().write_c_str(bytes, ptr, size)
}
- /// Helper function to write an OsStr as a 0x0000-terminated u16-sequence, which is what the
- /// Windows APIs usually handle.
- ///
- /// If `truncate == false` (the usual mode of operation), this function returns `Ok((false,
- /// length))` without trying to write if `size` is not large enough to fit the contents of
- /// `os_string` plus a null terminator. It returns `Ok((true, length))` if the writing process
- /// was successful. The string length returned does include the null terminator. Length is
- /// measured in units of `u16.`
- ///
- /// If `truncate == true`, then in case `size` is not large enough it *will* write the first
- /// `size.saturating_sub(1)` many items, followed by a null terminator (if `size > 0`).
- /// The return value is still `(false, length)` in that case.
- fn write_os_str_to_wide_str(
+ /// Internal helper to share code between `write_os_str_to_wide_str` and
+ /// `write_os_str_to_wide_str_truncated`.
+ fn write_os_str_to_wide_str_helper(
&mut self,
os_str: &OsStr,
ptr: Pointer