1
Fork 0

sparc64: fix crash in ABI code for { f64, f32 } struct

This would trigger a `Size::sub: 0 - 8 would result in negative size` abort,
if `data.last_offset > offset`.

This is almost hilariously easy to trigger (https://godbolt.org/z/8rbv57xET):

```rust
#[repr(C)]
pub struct DoubleFloat {
    f: f64,
    g: f32,
}

#[no_mangle]
pub extern "C" fn foo(x: DoubleFloat) {}
```

Tests for this will be covered by the cast-target-abi.rs test added in a later commit.
This commit is contained in:
Erik Desjardins 2024-03-17 00:11:54 -04:00
parent 4498cd6a8d
commit 41c6fa812b

View file

@ -35,6 +35,7 @@ where
data.last_offset = data.last_offset + Reg::i32().size; data.last_offset = data.last_offset + Reg::i32().size;
} }
if data.last_offset < offset {
for _ in 0..((offset - data.last_offset).bits() / 64) for _ in 0..((offset - data.last_offset).bits() / 64)
.min((data.prefix.len() - data.prefix_index) as u64) .min((data.prefix.len() - data.prefix_index) as u64)
{ {
@ -42,6 +43,7 @@ where
data.prefix_index += 1; data.prefix_index += 1;
data.last_offset = data.last_offset + Reg::i64().size; data.last_offset = data.last_offset + Reg::i64().size;
} }
}
if data.last_offset < offset { if data.last_offset < offset {
if data.prefix_index == data.prefix.len() { if data.prefix_index == data.prefix.len() {