Merge pull request #1721 from WildCryptoFox/remove-unsafe-code

remove the tiny bit of unsafe code
This commit is contained in:
David Tolnay
2020-01-17 14:13:35 -08:00
committed by GitHub
2 changed files with 3 additions and 3 deletions
+1
View File
@@ -120,6 +120,7 @@
)
)]
// Rustc lints.
#![forbid(unsafe_code)]
#![deny(missing_docs, unused_imports)]
////////////////////////////////////////////////////////////////////////////////
+2 -3
View File
@@ -633,8 +633,7 @@ impl Serialize for SystemTime {
#[cfg(feature = "std")]
macro_rules! serialize_display_bounded_length {
($value:expr, $max:expr, $serializer:expr) => {{
#[allow(deprecated)]
let mut buffer: [u8; $max] = unsafe { mem::uninitialized() };
let mut buffer: [u8; $max] = [0u8; $max];
let remaining_len = {
let mut remaining = &mut buffer[..];
write!(remaining, "{}", $value).unwrap();
@@ -646,7 +645,7 @@ macro_rules! serialize_display_bounded_length {
// write! only provides fmt::Formatter to Display implementations, which
// has methods write_str and write_char but no method to write arbitrary
// bytes. Therefore `written` must be valid UTF-8.
let written_str = unsafe { str::from_utf8_unchecked(written) };
let written_str = str::from_utf8(written).expect("must be valid UTF-8");
$serializer.serialize_str(written_str)
}};
}