diff --git a/Cargo.toml b/Cargo.toml index bcaf9373..20a65b46 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "thincollections" -version = "0.5.1" +version = "0.5.2" authors = ["Mohammad Rezaei "] license = "MIT/Apache-2.0" keywords = ["vector", "map", "set"] diff --git a/src/thin_v64.rs b/src/thin_v64.rs index 2111e56e..980704ac 100644 --- a/src/thin_v64.rs +++ b/src/thin_v64.rs @@ -526,7 +526,7 @@ impl V64 { unsafe { let len = self.len() - 1; self.set_len(len); - return ptr::read(1 as *const T); + return ptr::read(NonNull::dangling().as_ptr()); } } unsafe { @@ -697,7 +697,7 @@ impl V64 { let len = self.len(); assert!(index < len); self.set_len(len - 1); - return ptr::read(1 as *const T); + return ptr::read(NonNull::dangling().as_ptr()); } } let array: *mut T; @@ -772,7 +772,7 @@ impl V64 { if mem::size_of::() == 0 { let mut count = 0; unsafe { - let t: T = ptr::read(1 as *const T); + let t: T = ptr::read(NonNull::dangling().as_ptr()); for _i in 0..self.len() { if f(&t) { count += 1; } } @@ -1125,7 +1125,7 @@ impl V64 { if len > 0 { unsafe { self.set_len(len - 1); - return Some(ptr::read(1 as *const T)); + return Some(ptr::read(NonNull::dangling().as_ptr())); } } return None; @@ -1377,7 +1377,7 @@ impl V64 { pub fn into_boxed_slice(mut self) -> Box<[T]> { if mem::size_of::() == 0 { unsafe { - let slice = slice::from_raw_parts_mut(1 as *mut T, self.len()); + let slice = slice::from_raw_parts_mut(NonNull::dangling().as_ptr(), self.len()); let output: Box<[T]> = Box::from_raw(slice); return output; } @@ -1915,7 +1915,7 @@ impl Deref for V64 { fn deref(&self) -> &[T] { unsafe { - if mem::size_of::() == 0 { return slice::from_raw_parts(1 as *const T, self.len()); } + if mem::size_of::() == 0 { return slice::from_raw_parts(NonNull::dangling().as_ptr(), self.len()); } match self.control() { Control::Heap(ptr) => { let len_ptr = ptr as *mut usize; @@ -1935,7 +1935,7 @@ impl Deref for V64 { impl DerefMut for V64 { fn deref_mut(&mut self) -> &mut [T] { unsafe { - if mem::size_of::() == 0 { return slice::from_raw_parts_mut(1 as *mut T, self.len()); } + if mem::size_of::() == 0 { return slice::from_raw_parts_mut(NonNull::dangling().as_ptr(), self.len()); } match self.control() { Control::Heap(ptr) => { let len_ptr = ptr as *mut usize; @@ -2185,7 +2185,7 @@ impl Iterator for IntoIter { // Use a non-null pointer value // (self.ptr might be null because of wrapping) - Some(ptr::read(1 as *mut T)) + Some(ptr::read(NonNull::dangling().as_ptr())) } else { let old = self.ptr; self.ptr = self.ptr.offset(1); @@ -2224,7 +2224,7 @@ impl DoubleEndedIterator for IntoIter { // Use a non-null pointer value // (self.end might be null because of wrapping) - Some(ptr::read(1 as *mut T)) + Some(ptr::read(NonNull::dangling().as_ptr())) } else { self.end = self.end.offset(-1); diff --git a/src/thin_vec.rs b/src/thin_vec.rs index 4fa9f815..861190e7 100644 --- a/src/thin_vec.rs +++ b/src/thin_vec.rs @@ -623,7 +623,7 @@ impl ThinVec { unsafe { let len = self.len() - 1; self.set_len(len); - return ptr::read(1 as *const T); + return ptr::read(NonNull::dangling().as_ptr()); } } unsafe { @@ -723,7 +723,7 @@ impl ThinVec { let len = self.len(); assert!(index < len); self.set_len(len - 1); - return ptr::read(1 as *const T); + return ptr::read(NonNull::dangling().as_ptr()); } } let array: *mut T; @@ -776,7 +776,7 @@ impl ThinVec { if mem::size_of::() == 0 { let mut count = 0; unsafe { - let t: T = ptr::read(1 as *const T); + let t: T = ptr::read(NonNull::dangling().as_ptr()); for _i in 0..self.len() { if f(&t) { count += 1; } } @@ -1048,7 +1048,7 @@ impl ThinVec { if len > 0 { unsafe { self.set_len(len - 1); - return Some(ptr::read(1 as *const T)); + return Some(ptr::read(NonNull::dangling().as_ptr())); } } return None; @@ -1243,7 +1243,7 @@ impl ThinVec { pub fn into_boxed_slice(mut self) -> Box<[T]> { if mem::size_of::() == 0 { unsafe { - let slice = slice::from_raw_parts_mut(1 as *mut T, self.len()); + let slice = slice::from_raw_parts_mut(NonNull::dangling().as_ptr(), self.len()); let output: Box<[T]> = Box::from_raw(slice); return output; } @@ -1698,12 +1698,12 @@ impl Deref for ThinVec { fn deref(&self) -> &[T] { unsafe { - if mem::size_of::() == 0 { return slice::from_raw_parts(1 as *const T, self.len()); } + if mem::size_of::() == 0 { return slice::from_raw_parts(NonNull::dangling().as_ptr(), self.len()); } let len: usize; let arr: *mut T; if self.u.get() == DANGLE { len = 0; - arr = ptr::null_mut(); + arr = NonNull::dangling().as_ptr(); } else { let len_ptr = self.u.get() as *mut usize; len = *len_ptr; @@ -1717,12 +1717,12 @@ impl Deref for ThinVec { impl DerefMut for ThinVec { fn deref_mut(&mut self) -> &mut [T] { unsafe { - if mem::size_of::() == 0 { return slice::from_raw_parts_mut(1 as *mut T, self.len()); } + if mem::size_of::() == 0 { return slice::from_raw_parts_mut(NonNull::dangling().as_ptr(), self.len()); } let len: usize; let arr: *mut T; if self.u.get() == DANGLE { len = 0; - arr = ptr::null_mut(); + arr = NonNull::dangling().as_ptr(); } else { let len_ptr = self.u.get() as *mut usize; len = *len_ptr; @@ -1944,7 +1944,7 @@ impl Iterator for IntoIter { // Use a non-null pointer value // (self.ptr might be null because of wrapping) - Some(ptr::read(1 as *mut T)) + Some(ptr::read(NonNull::dangling().as_ptr())) } else { let old = self.ptr; self.ptr = self.ptr.offset(1); @@ -1983,7 +1983,7 @@ impl DoubleEndedIterator for IntoIter { // Use a non-null pointer value // (self.end might be null because of wrapping) - Some(ptr::read(1 as *mut T)) + Some(ptr::read(NonNull::dangling().as_ptr())) } else { self.end = self.end.offset(-1);