Skip to content
Snippets Groups Projects

Minor fixes to posix_memalign()

This MR changes the alignment check in posix_memalign() slightly. The spec states that alignment must be a "power of two multiple of sizeof(void *)", which I interpreted to mean "a-power-of-two times sizeof(void *)" when I originally wrote the code.

Both C11 and Rust's standard library seem to state that valid alignment requirements are always strictly powers of two. posix_memalign() is now slightly stricter to enforce this. There are two further implications to this change:

  • The new check is simpler and therefore, presumably, slightly faster
  • On a hypothetical platform with non-power-of-two pointer size, posix_memalign() will now never succeed (it would previously follow the happy path when called with an alignment of, say, 4*sizeof(void *)).

In addition, the function now also sets memptr to NULL upon errors. The old behaviour of leaving it untouched on error is also permitted by POSIX, but setting it to NULL may prevent some cases of reading from an uninitialized memptr in user code with inadequate error checks.

Merge request reports

Pipeline #7562 failed

Pipeline failed for da8d2fa7 on plimkilde:simplify-posix_memalign

Merged by Jeremy SollerJeremy Soller 4 years ago (May 24, 2020 7:18pm UTC)

Loading

Pipeline #7564 failed

Pipeline failed for 39346f5c on master

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Loading
  • Loading
Please register or sign in to reply
Loading