about summary refs log tree commit diff
path: root/library/alloc/src/string.rs
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2020-09-13 12:14:59 +0200
committerRalf Jung <post@ralfj.de>2020-09-15 23:14:41 +0200
commitc528d2419672bd4ace322ddbc000813a12c1d4c7 (patch)
tree869e53fda847a5ae86a36d89fbb6a865d74b463a /library/alloc/src/string.rs
parentd888725fba70af4139629da0f7a17910aa66d951 (diff)
downloadrust-c528d2419672bd4ace322ddbc000813a12c1d4c7.tar.gz
rust-c528d2419672bd4ace322ddbc000813a12c1d4c7.zip
fix slice::check_range aliasing problems
Diffstat (limited to 'library/alloc/src/string.rs')
-rw-r--r--library/alloc/src/string.rs3
1 files changed, 2 insertions, 1 deletions
diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs
index e1724bf3c9a..2b0ce5ede56 100644
--- a/library/alloc/src/string.rs
+++ b/library/alloc/src/string.rs
@@ -49,6 +49,7 @@ use core::iter::{FromIterator, FusedIterator};
 use core::ops::Bound::{Excluded, Included, Unbounded};
 use core::ops::{self, Add, AddAssign, Index, IndexMut, Range, RangeBounds};
 use core::ptr;
+use core::slice;
 use core::str::{lossy, pattern::Pattern};
 
 use crate::borrow::{Cow, ToOwned};
@@ -1506,7 +1507,7 @@ impl String {
         // of the vector version. The data is just plain bytes.
         // Because the range removal happens in Drop, if the Drain iterator is leaked,
         // the removal will not happen.
-        let Range { start, end } = self.as_bytes().check_range(range);
+        let Range { start, end } = slice::check_range(self.len(), range);
         assert!(self.is_char_boundary(start));
         assert!(self.is_char_boundary(end));