Closed
Description
The compiler version: rustc 1.67.0-nightly (c090c6880 2022-12-01)
As shown in the image in gdb:
- $8 is a ref to
Table
- $7 is a ref to
TableSlice
, returned byTable::AsRef
They have identical pointer value, 0x7ffffff782e0, but the rows
field in them are in different address. rows
of Table
is the correct one, while rows
of TableSlice
contains random data.
Further more, the rows
of TableSlice
has length = 93825009397280 (!!!).
The cause is in the implementation of Table::AsRef
. It force casts a &Table
into &TableSlice
, and when the layout of these two types are not the same, it'll cause trouble.
impl<'a> AsRef<TableSlice<'a>> for Table {
fn as_ref(&self) -> &TableSlice<'a> {
unsafe {
// All this is a bit hacky. Let's try to find something else
let s = &mut *((self as *const Table) as *mut Table);
s.rows.shrink_to_fit();
&*(self as *const Table as *const TableSlice<'a>)
}
}
}
Metadata
Metadata
Assignees
Labels
No labels