Fix read_blocked

This caused math to assert out because it never wrote into the buffer.

Now, presumably it wrote somewhere but I don't know where, so fixing
this seems like a good idea.

Fixes #9735.
This commit is contained in:
Fabian Boehm 2023-04-17 17:27:39 +02:00
parent 1bf29a5e13
commit 3bfe798dbb
2 changed files with 5 additions and 2 deletions

View file

@ -1433,9 +1433,9 @@ fn can_be_encoded(wc: char) -> bool {
/// Call read, blocking and repeating on EINTR. Exits on EAGAIN.
/// \return the number of bytes read, or 0 on EOF. On EAGAIN, returns -1 if nothing was read.
pub fn read_blocked(fd: RawFd, mut buf: &mut [u8]) -> isize {
pub fn read_blocked(fd: RawFd, buf: &mut [u8]) -> isize {
loop {
let res = unsafe { libc::read(fd, std::ptr::addr_of_mut!(buf).cast(), buf.len()) };
let res = unsafe { libc::read(fd, buf.as_mut_ptr().cast(), buf.len()) };
if res < 0 && errno::errno().0 == EINTR {
continue;
}

View file

@ -335,3 +335,6 @@ math 0x0_2.0_0_0P0_2
# CHECK: 8
math -0x8p-0_3
# CHECK: -1
echo 5 + 6 | math
# CHECK: 11