Skip to content

Commit 2f45e19

Browse files
committed
Fix BackingArray undefined behavior
`BackingArray` unsafe-impls `smallvec::Array`, which represents a promise to the smallvec crate that a raw pointer to BackingArray can be casted into a raw pointer to a u8. However, without this commit, this is undefined behavior, as the layout of Rust structs is unspecified unless a `repr` annotation is used to ensure a specific layout. This commit fixed this problem by marking `BackingArray` as `repr(transparent)` to ensure it has the same layout as `[u8; MAX_BYTES]`. This also fixes the `field `0` is never read` warning that previously occurred when running `cargo check`.
1 parent 0f7d15a commit 2f45e19

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

src/tree/node_text.rs

+1
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ mod inner {
237237

238238
/// The backing internal buffer type for `NodeText`.
239239
#[derive(Copy, Clone)]
240+
#[repr(transparent)]
240241
struct BackingArray([u8; MAX_BYTES]);
241242

242243
/// We need a very specific size of array, which is not necessarily

0 commit comments

Comments
 (0)