Skip to content

Dummy ComponentStorage casts are technically UB #69

@InspectorBoat

Description

@InspectorBoat

We commonly cast a type-erased ComponentStorage pointer to a Storage(u1) when we don't know its actual type, so that we perform component-agnostic operations on it.
This is technically undefined behavior, as there is no guarantee that the dummy type and the actual type have the same layout.
There are a few ways to fix this:

  • Marking the ComponentStorage struct as extern or packed is impossible because it contains auto layout structs.
    • We could make our own ArrayList and Allocator types so they could be extern, but that sucks for obvious reasons...
  • We could create a non-generic InnerComponentStorage type that holds all the fields, then have ComponentStorage simply be a type-safe wrapper around it.
  • Alternatively, we could make everything more generic, so that all component types are known at comptime. I personally prefer this one, as it would also fix @typeName is not guaranteed to be unique, and in fact has no guarantees #68.
  • Finally, we could just do nothing, as it doesn't seem to have caused any issues thus far...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions