squirrel-labs / ratatosk

Rask is a platformer game built with WASM and Rust
https://rask.rocks
MIT License
15 stars 1 forks source link

Fix UB in Key #69

Closed konsumlamm closed 4 years ago

konsumlamm commented 4 years ago

Key was defined as an enum with three variants and a from_u8 method (that should have been named from_u32) that transmuted a u32 to a Key:

#[repr(u32)]
pub enum Key {
    Unknown = 0,
    A = 2335202,
    Enter = 67114680,
}

That caused UB when the value was not one of 0, 2335202 or 67114680. This PR changes Key to a wrapper struct around a u32, with the variants becoming associated constants. from_u32 is replaced with a From<u32> implementation.