Skip to content

rd_kw_struct uses char *data which is UB. #1087

@eivindjahren

Description

@eivindjahren

The rd_kw_struct uses char *data to store different types (int, float, double, bool), then casts it to typed pointers:

return (ctype *)rd_kw->data; \

Compilers assume pointers of different types don't alias, enabling aggressive optimizations that can break the code.

It should either

  • Use std::aligned_storage and placement new
  • Use a union
  • Compile with -fno-strict-aliasing

We should probably also run tests with -fsanitize=undefined -fsanitize=address.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions