Skip to content

Fix clippy::ptr_offset_with_cast #149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/format/chapter/chapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ impl<'a> Chapter<'a> {
}

pub unsafe fn as_ptr(&self) -> *const AVChapter {
*(*self.context.as_ptr())
.chapters
.offset(self.index as isize)
*(*self.context.as_ptr()).chapters.add(self.index)
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/format/chapter/chapter_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ impl<'a> ChapterMut<'a> {
}

pub unsafe fn as_mut_ptr(&mut self) -> *mut AVChapter {
*(*self.context.as_mut_ptr())
.chapters
.offset(self.index as isize)
*(*self.context.as_mut_ptr()).chapters.add(self.index)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/format/stream/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl<'a> Stream<'a> {
}

pub unsafe fn as_ptr(&self) -> *const AVStream {
*(*self.context.as_ptr()).streams.offset(self.index as isize)
*(*self.context.as_ptr()).streams.add(self.index)
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/format/stream/stream_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ impl<'a> StreamMut<'a> {
}

pub unsafe fn as_mut_ptr(&mut self) -> *mut AVStream {
*(*self.context.as_mut_ptr())
.streams
.offset(self.index as isize)
*(*self.context.as_mut_ptr()).streams.add(self.index)
}
}

Expand Down
9 changes: 4 additions & 5 deletions src/util/format/sample.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use std::{
ffi::{CStr, CString},
mem,
ops::Index,
ptr, slice,
str::from_utf8_unchecked,
};

use libc::c_int;
use libc::{c_int, c_void};

use crate::ffi::{AVSampleFormat::*, *};

Expand Down Expand Up @@ -190,7 +189,7 @@ impl Index<usize> for Buffer {
panic!("out of bounds");
}

unsafe { slice::from_raw_parts(*self.buffer.offset(index as isize), self.size as usize) }
unsafe { slice::from_raw_parts(*self.buffer.add(index), self.size as usize) }
}
}

Expand All @@ -208,7 +207,7 @@ impl Clone for Buffer {
unsafe {
av_samples_copy(
self.buffer,
mem::transmute(source.buffer),
source.buffer as *const *mut u8,
0,
0,
source.samples as c_int,
Expand All @@ -223,7 +222,7 @@ impl Drop for Buffer {
#[inline]
fn drop(&mut self) {
unsafe {
av_freep(mem::transmute(self.buffer));
av_freep(self.buffer as *mut c_void);
}
}
}
9 changes: 2 additions & 7 deletions src/util/frame/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl Audio {
panic!("unsupported type");
}

unsafe { slice::from_raw_parts(mem::transmute((*self.as_ptr()).data[index]), self.samples()) }
unsafe { slice::from_raw_parts((*self.as_ptr()).data[index] as *const T, self.samples()) }
}

#[inline]
Expand All @@ -162,12 +162,7 @@ impl Audio {
panic!("unsupported type");
}

unsafe {
slice::from_raw_parts_mut(
mem::transmute((*self.as_mut_ptr()).data[index]),
self.samples(),
)
}
unsafe { slice::from_raw_parts_mut((*self.as_mut_ptr()).data[index] as *mut T, self.samples()) }
}

#[inline]
Expand Down
4 changes: 2 additions & 2 deletions src/util/frame/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ impl Video {

unsafe {
slice::from_raw_parts(
mem::transmute((*self.as_ptr()).data[index]),
(*self.as_ptr()).data[index] as *const T,
self.stride(index) * self.plane_height(index) as usize / mem::size_of::<T>(),
)
}
Expand All @@ -285,7 +285,7 @@ impl Video {

unsafe {
slice::from_raw_parts_mut(
mem::transmute((*self.as_mut_ptr()).data[index]),
(*self.as_mut_ptr()).data[index] as *mut T,
self.stride(index) * self.plane_height(index) as usize / mem::size_of::<T>(),
)
}
Expand Down