Skip to content

Commit

Permalink
fn GetBits::pos: Make return type a usize.
Browse files Browse the repository at this point in the history
  • Loading branch information
kkysen committed Jan 3, 2024
1 parent 44816ae commit 7d779f1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/getbits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl<'a> GetBits<'a> {
}

#[inline]
pub const fn pos(&self) -> c_uint {
self.index as c_uint * u8::BITS - self.bits_left as c_uint
pub const fn pos(&self) -> usize {
self.index * u8::BITS as usize - self.bits_left as usize
}
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ unsafe fn gen_picture(c: *mut Rav1dContext) -> Rav1dResult {
match res {
Err(_) => rav1d_data_unref_internal(in_0),
Ok(res) => {
if !(res as usize <= (*in_0).sz) {
if !(res <= (*in_0).sz) {
unreachable!();
}
(*in_0).sz = ((*in_0).sz as c_ulong).wrapping_sub(res as c_ulong) as usize as usize;
Expand Down
26 changes: 13 additions & 13 deletions src/obu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ use std::slice;
struct Debug {
enabled: bool,
name: &'static str,
start: c_uint,
start: usize,
}

impl Debug {
Expand Down Expand Up @@ -2100,8 +2100,8 @@ fn parse_tile_hdr(tiling: &Rav1dFrameHeader_tiling, gb: &mut GetBits) -> Rav1dTi
fn check_for_overrun(
c: &mut Rav1dContext,
gb: &mut GetBits,
init_bit_pos: c_uint,
obu_len: c_uint,
init_bit_pos: usize,
obu_len: usize,
) -> c_int {
// Make sure we haven't actually read past the end of the `gb` buffer
if gb.has_error() != 0 {
Expand All @@ -2127,8 +2127,8 @@ unsafe fn parse_obus(
c: &mut Rav1dContext,
r#in: &mut Rav1dData,
global: c_int,
) -> Rav1dResult<c_uint> {
unsafe fn skip(c: &mut Rav1dContext, len: c_uint, init_byte_pos: c_uint) -> c_uint {
) -> Rav1dResult<usize> {
unsafe fn skip(c: &mut Rav1dContext, len: usize, init_byte_pos: usize) -> usize {
// update refs with only the headers in case we skip the frame
for i in 0..8 {
if (*c.frame_hdr).refresh_frame_flags & (1 << i) != 0 {
Expand Down Expand Up @@ -2168,9 +2168,9 @@ unsafe fn parse_obus(

// obu length field
let len = if has_length_field != 0 {
gb.get_uleb128()
gb.get_uleb128() as usize
} else {
r#in.sz as c_uint - 1 - has_extension as c_uint
r#in.sz - 1 - has_extension as usize
};
if gb.has_error() != 0 {
return Err(EINVAL);
Expand All @@ -2186,7 +2186,7 @@ unsafe fn parse_obus(

// Make sure that there are enough bits left in the buffer
// for the rest of the OBU.
if len as usize > r#in.sz - init_byte_pos as usize {
if len > r#in.sz - init_byte_pos {
return Err(EINVAL);
}

Expand All @@ -2207,9 +2207,9 @@ unsafe fn parse_obus(
c: &mut Rav1dContext,
r#in: &mut Rav1dData,
gb: &mut GetBits,
init_bit_pos: c_uint,
init_byte_pos: c_uint,
len: c_uint,
init_bit_pos: usize,
init_byte_pos: usize,
len: usize,
) -> Rav1dResult {
if c.frame_hdr.is_null() {
return Err(EINVAL);
Expand Down Expand Up @@ -2473,7 +2473,7 @@ unsafe fn parse_obus(
while payload_size > 0
&& *r#in
.data
.offset((init_byte_pos + payload_size as c_uint - 1) as isize)
.offset((init_byte_pos + payload_size as usize - 1) as isize)
== 0
{
payload_size -= 1; // trailing_zero_bit x 8
Expand Down Expand Up @@ -2751,7 +2751,7 @@ pub(crate) unsafe fn rav1d_parse_obus(
c: &mut Rav1dContext,
r#in: &mut Rav1dData,
global: c_int,
) -> Rav1dResult<c_uint> {
) -> Rav1dResult<usize> {
parse_obus(c, r#in, global).inspect_err(|_| {
rav1d_data_props_copy(&mut c.cached_error_props, &mut r#in.m);
writeln!(c.logger, "Error parsing OBU data");
Expand Down

0 comments on commit 7d779f1

Please sign in to comment.