Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ldm0 committed Jan 3, 2024
1 parent 4360791 commit e9856b7
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/avutil/channel_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,22 @@ impl AVChannelLayout {
const BUF_SIZE: usize = 32;
let mut buf = vec![0u8; BUF_SIZE];

// Note: content_len doesn't include the trailing zero
//
// # Safety: after upgrading len is assumed to be positive.
let content_len = unsafe {
// # Safety: `as usize` after upgrading, len is assumed to be positive.
let len = unsafe {
ffi::av_channel_layout_describe(self.as_ptr(), buf.as_mut_ptr() as *mut i8, BUF_SIZE)
}
.upgrade()? as usize;

let content_len = if content_len >= BUF_SIZE {
buf.resize(content_len + 1, 0);
let len = if len > BUF_SIZE {
buf.resize(len, 0);
unsafe {
ffi::av_channel_layout_describe(self.as_ptr(), buf.as_mut_ptr() as *mut i8, content_len + 1)
ffi::av_channel_layout_describe(self.as_ptr(), buf.as_mut_ptr() as *mut i8, len)
}
.upgrade()? as usize
} else {
content_len
len
};
Ok(CString::new(&buf[..content_len]).unwrap())
Ok(CString::new(&buf[..len - 1]).unwrap())
}

/// Get the channel with the given index in a channel layout.
Expand Down

0 comments on commit e9856b7

Please sign in to comment.