Skip to content

Commit aada09f

Browse files
committed
Auto merge of rust-lang#2351 - RalfJung:readlink, r=RalfJung
extend a comment in readlink
2 parents 6bdc5d6 + c9b207e commit aada09f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/shims/unix/fs.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1639,6 +1639,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
16391639
let result = std::fs::read_link(pathname);
16401640
match result {
16411641
Ok(resolved) => {
1642+
// 'readlink' truncates the resolved path if the provided buffer is not large
1643+
// enough, and does *not* add a null terminator. That means we cannot use the usual
1644+
// `write_path_to_c_str` and have to re-implement parts of it ourselves.
16421645
let resolved = this.convert_path_separator(
16431646
Cow::Borrowed(resolved.as_ref()),
16441647
crate::shims::os_str::PathConversion::HostToTarget,
@@ -1648,8 +1651,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
16481651
if path_bytes.len() > bufsize {
16491652
path_bytes = &path_bytes[..bufsize]
16501653
}
1651-
// 'readlink' truncates the resolved path if
1652-
// the provided buffer is not large enough.
16531654
this.write_bytes_ptr(buf, path_bytes.iter().copied())?;
16541655
Ok(path_bytes.len().try_into().unwrap())
16551656
}

0 commit comments

Comments
 (0)