Skip to content

Commit bccc2f2

Browse files
authored
pcm: Fix error code reporting of std::io::Read impl for IO type (#144)
The error code passed to std::io::Error::from_raw_os_error() should be positive, as the various examples of it illustrate. Negate the r value to make sure it is as expected.
1 parent d1a0bbb commit bccc2f2

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/pcm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ impl<'a, S: Copy> std::io::Read for IO<'a, S> {
468468
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
469469
let size = self.0.bytes_to_frames(buf.len() as isize) as alsa::snd_pcm_uframes_t; // TODO: Do we need to check for overflow here?
470470
let r = unsafe { alsa::snd_pcm_readi((self.0).0, buf.as_mut_ptr() as *mut c_void, size) };
471-
if r < 0 { Err(std::io::Error::from_raw_os_error(r as i32)) }
471+
if r < 0 { Err(std::io::Error::from_raw_os_error(-r as i32)) }
472472
else { Ok(self.0.frames_to_bytes(r) as usize) }
473473
}
474474
}

0 commit comments

Comments
 (0)