about summary refs log tree commit diff
path: root/src/test/codegen/src-hash-algorithm/src-hash-algorithm-sha1.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-09-02 15:23:08 +0000
committerbors <bors@rust-lang.org>2020-09-02 15:23:08 +0000
commit95815c9b2b222d865c227d717b1c152072ddf25a (patch)
tree61eae3de079bb754155d34785df2279958cc1976 /src/test/codegen/src-hash-algorithm/src-hash-algorithm-sha1.rs
parentda897dfb6daa268a965d2d73620316ba56020a19 (diff)
parent56129d39c0d6f0e15e2f4fc40b8079b8b22e34fe (diff)
downloadrust-95815c9b2b222d865c227d717b1c152072ddf25a.tar.gz
rust-95815c9b2b222d865c227d717b1c152072ddf25a.zip
Auto merge of #76241 - RalfJung:flt2dec, r=Mark-Simulacrum
flt2dec: properly handle uninitialized memory

The float-to-str code currently uses uninitialized memory incorrectly (see https://github.com/rust-lang/rust/issues/76092). This PR fixes that.

Specifically, that code used `&mut [T]` as "out references", but it would be incorrect for the caller to actually pass uninitialized memory. So the PR changes this to `&mut [MaybeUninit<T>]`, and then functions return a `&[T]` to the part of the buffer that they initialized (some functions already did that, indirectly via `&Formatted`, others were adjusted to return that buffer instead of just the initialized length).

What I particularly like about this is that it moves `unsafe` to the right place: previously, the outermost caller had to use `unsafe` to assert that things are initialized; now it is the functions that do the actual initializing which have the corresponding `unsafe` block when they call `MaybeUninit::slice_get_ref` (renamed in https://github.com/rust-lang/rust/pull/76217 to `slice_assume_init_ref`).

Reviewers please be aware that I have no idea how any of this code actually works. My changes were purely mechanical and type-driven. The test suite passes so I guess I didn't screw up badly...

Cc @sfackler this is somewhat related to your RFC, and possibly some of this code could benefit from (a generalized version of) the API you describe there. But for now I think what I did is "good enough".

Fixes https://github.com/rust-lang/rust/issues/76092.
Diffstat (limited to 'src/test/codegen/src-hash-algorithm/src-hash-algorithm-sha1.rs')
0 files changed, 0 insertions, 0 deletions