fix some uses of pointer intrinsics with invalid pointers
This commit is contained in:
@@ -2410,9 +2410,8 @@ impl<T> Iterator for IntoIter<T> {
|
|||||||
// same pointer.
|
// same pointer.
|
||||||
self.ptr = arith_offset(self.ptr as *const i8, 1) as *mut T;
|
self.ptr = arith_offset(self.ptr as *const i8, 1) as *mut T;
|
||||||
|
|
||||||
// Use a non-null pointer value
|
// Read from a properly aligned pointer to make up a value of this ZST.
|
||||||
// (self.ptr might be null because of wrapping)
|
Some(ptr::read(NonNull::dangling().as_ptr()))
|
||||||
Some(ptr::read(1 as *mut T))
|
|
||||||
} else {
|
} else {
|
||||||
let old = self.ptr;
|
let old = self.ptr;
|
||||||
self.ptr = self.ptr.offset(1);
|
self.ptr = self.ptr.offset(1);
|
||||||
@@ -2451,9 +2450,8 @@ impl<T> DoubleEndedIterator for IntoIter<T> {
|
|||||||
// See above for why 'ptr.offset' isn't used
|
// See above for why 'ptr.offset' isn't used
|
||||||
self.end = arith_offset(self.end as *const i8, -1) as *mut T;
|
self.end = arith_offset(self.end as *const i8, -1) as *mut T;
|
||||||
|
|
||||||
// Use a non-null pointer value
|
// Read from a properly aligned pointer to make up a value of this ZST.
|
||||||
// (self.end might be null because of wrapping)
|
Some(ptr::read(NonNull::dangling().as_ptr()))
|
||||||
Some(ptr::read(1 as *mut T))
|
|
||||||
} else {
|
} else {
|
||||||
self.end = self.end.offset(-1);
|
self.end = self.end.offset(-1);
|
||||||
|
|
||||||
|
|||||||
@@ -742,7 +742,9 @@ impl<K, V> RawTable<K, V> {
|
|||||||
) -> Result<RawTable<K, V>, CollectionAllocErr> {
|
) -> Result<RawTable<K, V>, CollectionAllocErr> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ret = RawTable::new_uninitialized_internal(capacity, fallibility)?;
|
let ret = RawTable::new_uninitialized_internal(capacity, fallibility)?;
|
||||||
|
if capacity > 0 {
|
||||||
ptr::write_bytes(ret.hashes.ptr(), 0, capacity);
|
ptr::write_bytes(ret.hashes.ptr(), 0, capacity);
|
||||||
|
}
|
||||||
Ok(ret)
|
Ok(ret)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user