From 223817447850dbf9f07ce51c6c2701a484d70050 Mon Sep 17 00:00:00 2001 From: Zhiming Wang Date: Sun, 26 Jul 2020 01:01:21 +0800 Subject: [PATCH 1/2] Fix clippy::ptr_offset_with_cast --- src/format/chapter/chapter.rs | 4 +--- src/format/chapter/chapter_mut.rs | 4 +--- src/format/stream/stream.rs | 2 +- src/format/stream/stream_mut.rs | 4 +--- src/util/format/sample.rs | 2 +- 5 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/format/chapter/chapter.rs b/src/format/chapter/chapter.rs index db3d9d2f..05c88a75 100644 --- a/src/format/chapter/chapter.rs +++ b/src/format/chapter/chapter.rs @@ -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) } } diff --git a/src/format/chapter/chapter_mut.rs b/src/format/chapter/chapter_mut.rs index 6ab81746..33b7d693 100644 --- a/src/format/chapter/chapter_mut.rs +++ b/src/format/chapter/chapter_mut.rs @@ -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) } } diff --git a/src/format/stream/stream.rs b/src/format/stream/stream.rs index 6e229ba7..ef366828 100644 --- a/src/format/stream/stream.rs +++ b/src/format/stream/stream.rs @@ -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) } } diff --git a/src/format/stream/stream_mut.rs b/src/format/stream/stream_mut.rs index 6e32cd4d..f04be916 100644 --- a/src/format/stream/stream_mut.rs +++ b/src/format/stream/stream_mut.rs @@ -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) } } diff --git a/src/util/format/sample.rs b/src/util/format/sample.rs index 4cfebb49..48b53343 100644 --- a/src/util/format/sample.rs +++ b/src/util/format/sample.rs @@ -190,7 +190,7 @@ impl Index 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) } } } From 517f1a729b9c7a1f29dd6c06df25fd4c275f60ca Mon Sep 17 00:00:00 2001 From: Zhiming Wang Date: Sun, 26 Jul 2020 01:01:32 +0800 Subject: [PATCH 2/2] Fix clippy::transmute_ptr_to_ptr --- src/util/format/sample.rs | 7 +++---- src/util/frame/audio.rs | 9 ++------- src/util/frame/video.rs | 4 ++-- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/util/format/sample.rs b/src/util/format/sample.rs index 48b53343..87ff452a 100644 --- a/src/util/format/sample.rs +++ b/src/util/format/sample.rs @@ -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::*, *}; @@ -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, @@ -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); } } } diff --git a/src/util/frame/audio.rs b/src/util/frame/audio.rs index bf2acf8b..ebec623f 100644 --- a/src/util/frame/audio.rs +++ b/src/util/frame/audio.rs @@ -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] @@ -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] diff --git a/src/util/frame/video.rs b/src/util/frame/video.rs index e1497fe6..f5685859 100644 --- a/src/util/frame/video.rs +++ b/src/util/frame/video.rs @@ -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::(), ) } @@ -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::(), ) }