Skip to content

Fix pointer math.#22

Merged
JohnTitor merged 2 commits intoJohnTitor:masterfrom
jsirois:panic/fix
Feb 15, 2024
Merged

Fix pointer math.#22
JohnTitor merged 2 commits intoJohnTitor:masterfrom
jsirois:panic/fix

Conversation

@jsirois
Copy link
Copy Markdown
Contributor

@jsirois jsirois commented Feb 12, 2024

The previous use of get_unchecked was UB according to
https://doc.rust-lang.org/nightly/std/primitive.slice.html#safety-2
and rust-lang/rust#120594 exposed this leading
to a panic caught by tests as:

cargo test --all
...
thread 'fold::tests::ident_transformation_in_defs' panicked at library/core/src/panicking.rs:155:5:
unsafe precondition(s) violated: hint::assert_unchecked must never be called when the condition is false
thread caused non-unwinding panic. aborting.
error: test failed, to rerun pass `-p garando_syntax --lib`
...

Fixes rust-lang/rust#120910

The previous use of `get_unchecked` was UB according to
https://doc.rust-lang.org/nightly/std/primitive.slice.html#safety-2
and rust-lang/rust#120594 exposed this leading
to a panic caught by out tests as:
```
cargo test --all
...
thread 'fold::tests::ident_transformation_in_defs' panicked at library/core/src/panicking.rs:155:5:
unsafe precondition(s) violated: hint::assert_unchecked must never be called when the condition is false
thread caused non-unwinding panic. aborting.
error: test failed, to rerun pass `-p garando_syntax --lib`
...
```

Fixes rust-lang/rust#120910
// move the read_i'th item out of the vector and map it
// to an iterator
let e = ptr::read(self.get_unchecked(read_i));
let e = ptr::read(self.as_mut_ptr().offset(read_i as isize));
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not comment these casts but I'm a noob to this sort of manipulation in Rust.

My reading of https://doc.rust-lang.org/reference/type-layout.html#primitive-data-layout, though, particularly "usize and isize have a size big enough to contain every address on the target platform.", seems to suggest this is always OK.

Copy link
Copy Markdown
Owner

@JohnTitor JohnTitor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@JohnTitor JohnTitor merged commit fe30dd8 into JohnTitor:master Feb 15, 2024
@ehuss
Copy link
Copy Markdown

ehuss commented Feb 15, 2024

@JohnTitor Would it be possible to get a new release of garando_syntax with this change?

It seems like there are some other unreleased changes, like 5c993df, which is a semver breakage and might also require a new version of ctest2?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

libc-test panic: unsafe precondition(s) violated: hint::assert_unchecked must never be called when the condition is false

3 participants