Skip to content

Commit 83bc861

Browse files
authored
Don't truncate the last character in ttyname (#832)
CStr::len(), as used in backend::libc::termios::syscalls::ttyname, does not include the trailing NUL. But CString::from_vec_with_nul_unchecked requires the NUL to be present. Without it, it drops off the last character from the string. This led to it returning paths like "/dev/pts/" instead of "/dev/pts/8". Tested on FreeBSD and Linux x86_64
1 parent 4358096 commit 83bc861

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/termios/tty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ fn _ttyname(dirfd: BorrowedFd<'_>, mut buffer: Vec<u8>) -> io::Result<CString> {
5454
buffer.reserve(buffer.capacity() + 1); // use `Vec` reallocation strategy to grow capacity exponentially
5555
}
5656
Ok(len) => {
57-
// SAFETY: assume the backend returns the length of the string
57+
// SAFETY: assume the backend returns the length of the string excluding the NUL.
5858
unsafe {
59-
buffer.set_len(len);
59+
buffer.set_len(len + 1);
6060
}
6161

6262
// SAFETY:

0 commit comments

Comments
 (0)