Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove use of MaybeUninit in our float writers. #117

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/Miri.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Miri

on: [workflow_dispatch]
jobs:
Miri:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly
- run: cargo check
- run: cargo build
- run: rustup component add --toolchain nightly miri
# Test with all features: this won't test the non-compact code paths however
- run: cargo miri test --all-features
- run: cargo miri test --features radix,format,write-integers,write-floats,parse-integers,parse-floats
15 changes: 15 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Added fuzzing and miri code safety analysis to our CI pipelines.
- Removed requirement of `alloc` in `no_std` ennvironments without the `write` feature.

### Changed

- Updated the MSRV to 1.63.0 (1.65.0 for development).
- Improved performance due to compiler regressions in rustc 1.81.0 and above.

### Fixed

- Removed use of undefined behavior in `MaybeUninit`.
- Provide better safety documentation.
- Parsing of Ruby float literals.
- Performance regressions in Rust 1.81.0+.
- Removed incorrect bounds checking in reading from iterators.
- Overflow checking with integer parsing.
- Writing `-0.0` with a leading `-`.

### Removed

- Support for mips (MIPS), mipsel (MIPS LE), mips64 (MIPS64 BE), and mips64el (MIPS64 LE) on Linux.
Expand Down
5 changes: 1 addition & 4 deletions lexical-write-float/src/compact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use crate::float::{ExtendedFloat80, RawFloat};
use crate::options::Options;
use crate::shared;
use crate::table::GRISU_POWERS_OF_TEN;
use core::mem;
use lexical_util::algorithm::rtrim_char_count;
#[cfg(feature = "f16")]
use lexical_util::bf16::bf16;
Expand Down Expand Up @@ -64,9 +63,7 @@ pub unsafe fn write_float<F: RawFloat, const FORMAT: u128>(
debug_assert!(float >= F::ZERO);

// Write our mantissa digits to a temporary buffer.
let digits: mem::MaybeUninit<[u8; 32]> = mem::MaybeUninit::uninit();
// SAFETY: safe, since we never read bytes that weren't written.
let mut digits = unsafe { digits.assume_init() };
let mut digits: [u8; 32] = [0u8; 32];
let (digit_count, kappa, carried) = if float == F::ZERO {
// SAFETY: safe since `digits.len() == 32`.
unsafe { index_unchecked_mut!(digits[0]) = b'0' };
Expand Down
6 changes: 1 addition & 5 deletions lexical-write-float/src/radix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

use crate::options::{Options, RoundMode};
use crate::shared;
use core::mem;
use lexical_util::algorithm::{ltrim_char_count, rtrim_char_count};
use lexical_util::constants::{FormattedSize, BUFFER_SIZE};
use lexical_util::digit::{char_to_digit_const, digit_to_char_const};
Expand Down Expand Up @@ -67,10 +66,7 @@ where
// either way, with additional space for sign, decimal point and string
// termination should be sufficient.
const SIZE: usize = 2200;
let buffer: mem::MaybeUninit<[u8; SIZE]> = mem::MaybeUninit::uninit();
// SAFETY: safe, since we never read bytes that weren't written.
let mut buffer = unsafe { buffer.assume_init() };
//let buffer = buffer.as_mut_ptr();
let mut buffer = [0u8; SIZE];
let initial_cursor: usize = SIZE / 2;
let mut integer_cursor = initial_cursor;
let mut fraction_cursor = initial_cursor;
Expand Down