Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lot of functions are unsound #27

Open
SkiFire13 opened this issue Jun 11, 2024 · 0 comments
Open

Lot of functions are unsound #27

SkiFire13 opened this issue Jun 11, 2024 · 0 comments

Comments

@SkiFire13
Copy link

Just a few examples I found very quickly.

  • Entity::set seems to be creating a &mut T reference to either uninitialized or zeroed memory (both UB if done for an arbitrary type like Box or String) and writes a T to it (which means dropping the "old" T at that memory location, which never existed in the first place)

  • World::get and Entity::get allow to get a &T to some component, but don't prevent any other method that mutate that component (like World::set, Entity::set or Entity::remove) from running. The methods that mutate or remove the components should likely take a &mut, though that's probably not enough (see the next point).

  • Entity is Copy, so the &mut self requirement on the get_mut doesn't really prevent it from being called multiple times on the same entity. Moreover even if Entity was not Copy/Clone you could still create an aliased one by using World::lookup or World::find_entity.

I suspect there are a lot more functions or ways to generate UB in this crate. Ideally most if not all functions would be marked as unsafe, but if this is unwanted for ergonomic reasons at least put a big disclaimer in the README and the documentation that this crate is unsound and can easily run into UB by using safe functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant