Skip to content

Commit 035b142

Browse files
committed
update align to avoid signed cast and clang warning
This does change the compiled result for all of gcc, clang, msvc.
1 parent 9b45b23 commit 035b142

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

include/decodeless/allocator.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ class linear_memory_resource {
133133
}
134134

135135
[[nodiscard]] constexpr void* allocate(std::size_t bytes, std::size_t align) {
136-
// Align
137-
uintptr_t result = m_next + ((-static_cast<ptrdiff_t>(m_next)) & (align - 1));
136+
// Align, assumes 'align' is a power of two
137+
uintptr_t result = (m_next + align - 1) & ~(align - 1);
138138

139139
// Allocate
140140
uintptr_t newNext = result + bytes;

0 commit comments

Comments
 (0)