Skip to content

Conversation

@matt-dbs
Copy link

@matt-dbs matt-dbs commented Dec 9, 2025

In Graph::serialize_mmap, pos is set to a non-4-byte aligned pointer and is then dereferenced as various other types. This is Undefined Behavior with respect to the C++ standard, due to both writing through unaligned pointers and breaking strict aliasing rules.

This change replaces such writes with memcpy that has an exception in the standard to bypass both aliasing and alignment restrictions.

This is not the only alignment/aliasing issue in this function; it looks like operations involving end_of_lastrank and mapping_start also break these rules. But these are left as-is for now.

In `Graph::serialize_mmap`, `pos` is set to a non-4-byte aligned pointer and is
then dereferenced as various other types. This is Undefined Behavior with
respect to the C++ standard, due to both writing through unaligned pointers and
breaking strict aliasing rules.

This change replaces such writes with `memcpy` that has an exception in the
standard to bypass both aliasing and alignment restrictions.

This is not the only alignment/aliasing issue in this function; it looks like
operations involving `end_of_lastrank` and `mapping_start` also break these
rules. But these are left as-is for now.
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

Successfully merging this pull request may close these issues.

1 participant