Skip to content

Commit e80446c

Browse files
authored
Merge pull request #102 from gnzlbg/ub
Fix undefined behavior in DerefMut of ArrayString
2 parents 21034b3 + 9f57879 commit e80446c

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

src/array_string.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::borrow::Borrow;
22
use std::cmp;
33
use std::fmt;
44
use std::hash::{Hash, Hasher};
5-
use std::mem;
65
use std::ptr;
76
use std::ops::{Deref, DerefMut};
87
use std::str;
@@ -360,8 +359,7 @@ impl<A: Array<Item=u8>> DerefMut for ArrayString<A> {
360359
fn deref_mut(&mut self) -> &mut str {
361360
unsafe {
362361
let sl = slice::from_raw_parts_mut(self.xs.as_mut_ptr(), self.len.to_usize());
363-
// FIXME: Nothing but transmute to do this right now
364-
mem::transmute(sl)
362+
str::from_utf8_unchecked_mut(sl)
365363
}
366364
}
367365
}

0 commit comments

Comments
 (0)