-
Notifications
You must be signed in to change notification settings - Fork 16
fix(sallyport): mark copy_into_slice unsafe #190
Conversation
1ffa4c4 to
411388e
Compare
411388e to
840f0b8
Compare
840f0b8 to
087a62d
Compare
087a62d to
1004fb1
Compare
|
Needs #188 first |
c57c5ff to
1856357
Compare
src/sallyport/mod.rs
Outdated
| Ok((c, dst)) | ||
| } | ||
|
|
||
| /// Copies data from a slice into the cursor buffer using self.alloc(). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to this PR, but should this not be "copies from a cursor buffer into a slice"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
src/sallyport/mod.rs
Outdated
|
|
||
| let mut slab_all = [0usize; 3]; | ||
|
|
||
| let c = unsafe { c.copy_into_slice::<usize>(4, &mut slab_all, 3) }?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the src_len a 4 here? That is shorter than the total slab 1-3 values but longer than slab_all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is the amount of elements the cursor should advance after copying.
`Cursor::copy_into_slice` has to be unsafe, otherwise it is possible to fill in a slice of e.g. bools with invalid values using safe rust code. This patch also adds a test calling `Cursor::copy_into_slice()` and simplifies the method by removing a parameter and calling existing methods. Signed-off-by: Harald Hoyer <[email protected]>
1856357 to
5594001
Compare
|
Ok, I didn't see the forest because of all the trees... simplified the method by removing |
fix(sallyport): mark copy_into_slice unsafe
Cursor::copy_into_slicehas to be unsafe, otherwise it is possible tofill in a slice of e.g. bools with invalid values using safe rust code.
This patch also adds a test calling
Cursor::copy_into_slice()andsimplifies the method by removing a parameter and calling existing
methods.