Skip to content

Commit

Permalink
Remove UB form is_aligned
Browse files Browse the repository at this point in the history
Technically, testing alignment by converting the pointer to integer is
undefined behavior. In this PR, we use std::align for the purpose of
testing.
  • Loading branch information
WeiqunZhang committed Feb 10, 2024
1 parent 24b3604 commit acd1a1d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Src/Base/AMReX_Arena.H
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ inline std::size_t aligned_size (std::size_t align_requirement, std::size_t size

inline bool is_aligned (const void* p, std::size_t alignment) noexcept
{
return (reinterpret_cast<std::size_t>(p) % alignment) == 0;
auto* q = const_cast<void*>(p);
auto space = alignment;
return std::align(alignment, alignment, q, space) == p;
}

class Arena;
Expand Down

0 comments on commit acd1a1d

Please sign in to comment.