Skip to content

Commit 0af1c7b

Browse files
committed
Fix pointer math.
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
1 parent ef91102 commit 0af1c7b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

garando_syntax/src/util/move_map.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ impl<T> MoveMap<T> for Vec<T> {
2929
while read_i < old_len {
3030
// move the read_i'th item out of the vector and map it
3131
// to an iterator
32-
let e = ptr::read(self.get_unchecked(read_i));
32+
let e = ptr::read(self.as_mut_ptr().offset(read_i as isize));
3333
let iter = f(e).into_iter();
3434
read_i += 1;
3535

3636
for e in iter {
3737
if write_i < read_i {
38-
ptr::write(self.get_unchecked_mut(write_i), e);
38+
ptr::write(self.as_mut_ptr().offset(write_i as isize), e);
3939
write_i += 1;
4040
} else {
4141
// If this is reached we ran out of space

0 commit comments

Comments
 (0)