From 9f5787902860c37569bade928405dea1915f6ed4 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Fri, 31 Aug 2018 22:43:05 +0200 Subject: [PATCH] fix undefined behavior in DerefMut of ArrayString --- src/array_string.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/array_string.rs b/src/array_string.rs index 0dc0974..190ae15 100644 --- a/src/array_string.rs +++ b/src/array_string.rs @@ -2,7 +2,6 @@ use std::borrow::Borrow; use std::cmp; use std::fmt; use std::hash::{Hash, Hasher}; -use std::mem; use std::ptr; use std::ops::{Deref, DerefMut}; use std::str; @@ -360,8 +359,7 @@ impl> DerefMut for ArrayString { fn deref_mut(&mut self) -> &mut str { unsafe { let sl = slice::from_raw_parts_mut(self.xs.as_mut_ptr(), self.len.to_usize()); - // FIXME: Nothing but transmute to do this right now - mem::transmute(sl) + str::from_utf8_unchecked_mut(sl) } } }