Skip to content

Fix pointer truncation and under-alignment in ALIGN() on LLP64 platforms - #148

Open
kevinushey wants to merge 1 commit into
laurikari:masterfrom
kevinushey:bugfix/align-llp64
Open

Fix pointer truncation and under-alignment in ALIGN() on LLP64 platforms#148
kevinushey wants to merge 1 commit into
laurikari:masterfrom
kevinushey:bugfix/align-llp64

Conversation

@kevinushey

Copy link
Copy Markdown

ALIGN() computes the padding needed to align a pointer by casting it through long. That has two problems on LLP64 platforms (64-bit Windows), where long is 32 bits:

  • the cast truncates the pointer before the remainder is computed, so the padding itself can be wrong; and
  • the buffers carved up with ALIGN(..., long) in tre-mem.c, tre-match-parallel.c, and tre-match-approx.c store pointers and structs containing pointers, which need 8-byte alignment, while sizeof(long) is 4.

This changes the cast to size_t and introduces a tre_aligned_t union (pointer, function pointer, long long, double) used as the alignment type at all call sites.

No functional change on LP64 platforms, where long already has pointer width. make check passes on macOS arm64 (clang). R's bundled copy of TRE has carried an equivalent fix for its 64-bit Windows builds for many years.

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