*: check unsafe slice creation

This commit is contained in:
Euan Rochester 2016-05-01 00:11:39 +01:00 committed by meh
parent ca907c57f3
commit fafcf1d433
4 changed files with 11 additions and 10 deletions

View File

@ -88,13 +88,15 @@ impl<'a> Vector<'a> {
pub fn coefficients(&self) -> &[f64] {
unsafe {
slice::from_raw_parts((*self.as_ptr()).coeff, (*self.as_ptr()).length as usize)
slice::from_raw_parts((*self.as_ptr()).coeff,
(*self.as_ptr()).length as usize)
}
}
pub fn coefficients_mut(&self) -> &[f64] {
unsafe {
slice::from_raw_parts_mut((*self.as_ptr()).coeff, (*self.as_ptr()).length as usize)
slice::from_raw_parts_mut((*self.as_ptr()).coeff,
(*self.as_ptr()).length as usize)
}
}
}

View File

@ -177,7 +177,8 @@ impl Index<usize> for Buffer {
}
unsafe {
slice::from_raw_parts(*self.buffer.offset(index as isize), self.size as usize)
slice::from_raw_parts(*self.buffer.offset(index as isize),
self.size as usize)
}
}
}

View File

@ -157,9 +157,8 @@ impl Audio {
}
unsafe {
slice::from_raw_parts(
mem::transmute((*self.as_ptr()).data[index]),
mem::size_of::<T>() * self.samples())
slice::from_raw_parts(mem::transmute((*self.as_ptr()).data[index]),
self.samples())
}
}
@ -174,9 +173,8 @@ impl Audio {
}
unsafe {
slice::from_raw_parts_mut(
mem::transmute((*self.as_mut_ptr()).data[index]),
mem::size_of::<T>() * self.samples())
slice::from_raw_parts_mut(mem::transmute((*self.as_mut_ptr()).data[index]),
self.samples())
}
}

View File

@ -252,7 +252,7 @@ impl Video {
}
#[inline]
pub fn plane_mut<T: Component>(&mut self, index: usize) -> &mut[T] {
pub fn plane_mut<T: Component>(&mut self, index: usize) -> &mut [T] {
if index >= self.planes() {
panic!("out of bounds");
}