]> git.lizzy.rs Git - rust.git/commitdiff
Remove unsafe `unsafe` inner function.
authorCorey Farwell <coreyf@rwell.org>
Mon, 26 Nov 2018 13:40:34 +0000 (08:40 -0500)
committerCorey Farwell <coreyf@rwell.org>
Mon, 26 Nov 2018 14:12:32 +0000 (09:12 -0500)
Within this `Iterator` implementation, a function `unsafe_get` is
defined which unsafely allows _unchecked_ indexing of any element in a
slice. This should be marked as _unsafe_, but it is not.

To address this issue, I removed that inner function.

src/libcore/str/lossy.rs

index 186d6adbc91cf67ecb6c88df1acf286c943cebf4..52abd8f99529b586b00b6d665d2d0509d112003a 100644 (file)
@@ -62,18 +62,15 @@ fn next(&mut self) -> Option<Utf8LossyChunk<'a>> {
         }
 
         const TAG_CONT_U8: u8 = 128;
-        fn unsafe_get(xs: &[u8], i: usize) -> u8 {
-            unsafe { *xs.get_unchecked(i) }
-        }
         fn safe_get(xs: &[u8], i: usize) -> u8 {
-            if i >= xs.len() { 0 } else { unsafe_get(xs, i) }
+            *xs.get(i).unwrap_or(&0)
         }
 
         let mut i = 0;
         while i < self.source.len() {
             let i_ = i;
 
-            let byte = unsafe_get(self.source, i);
+            let byte = unsafe { *self.source.get_unchecked(i) };
             i += 1;
 
             if byte < 128 {