Liballoc DoubleEndedIterator limit unsafe to pointer arithmethic
This commit is contained in:
parent
cc0d634550
commit
50315238aa
1 changed files with 11 additions and 15 deletions
|
@ -2703,7 +2703,7 @@ impl<T> Iterator for IntoIter<T> {
|
||||||
// purposefully don't use 'ptr.offset' because for
|
// purposefully don't use 'ptr.offset' because for
|
||||||
// vectors with 0-size elements this would return the
|
// vectors with 0-size elements this would return the
|
||||||
// same pointer.
|
// same pointer.
|
||||||
self.ptr = unsafe { arith_offset(self.ptr as *const T, 1) as *mut T };
|
self.ptr = unsafe { arith_offset(self.ptr as *const i8, 1) as *mut T };
|
||||||
|
|
||||||
// Make up a value of this ZST.
|
// Make up a value of this ZST.
|
||||||
Some(unsafe { mem::zeroed() })
|
Some(unsafe { mem::zeroed() })
|
||||||
|
@ -2735,22 +2735,18 @@ impl<T> Iterator for IntoIter<T> {
|
||||||
impl<T> DoubleEndedIterator for IntoIter<T> {
|
impl<T> DoubleEndedIterator for IntoIter<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn next_back(&mut self) -> Option<T> {
|
fn next_back(&mut self) -> Option<T> {
|
||||||
unsafe {
|
if self.end == self.ptr {
|
||||||
if self.end == self.ptr {
|
None
|
||||||
None
|
} else if mem::size_of::<T>() == 0 {
|
||||||
} else {
|
// See above for why 'ptr.offset' isn't used
|
||||||
if mem::size_of::<T>() == 0 {
|
self.end = unsafe { arith_offset(self.end as *const i8, -1) as *mut T };
|
||||||
// See above for why 'ptr.offset' isn't used
|
|
||||||
self.end = arith_offset(self.end as *const i8, -1) as *mut T;
|
|
||||||
|
|
||||||
// Make up a value of this ZST.
|
// Make up a value of this ZST.
|
||||||
Some(mem::zeroed())
|
Some(unsafe { mem::zeroed() })
|
||||||
} else {
|
} else {
|
||||||
self.end = self.end.offset(-1);
|
self.end = unsafe { self.end.offset(-1) };
|
||||||
|
|
||||||
Some(ptr::read(self.end))
|
Some(unsafe { ptr::read(self.end) })
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue