Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Skip to content
Commit bc7d6c0a authored by Bernie Innocenti's avatar Bernie Innocenti
Browse files

Sanitize buffer alignment macros

The ancient ALIGN() macros caused clang-tidy to complain:

packages/modules/DnsResolver/gethnamaddr.cpp:367:10: error: integer to
pointer cast pessimizes optimization opportunities
[performance-no-int-to-ptr,-warnings-as-errors]
    bp = (char*) ALIGN(bp);

The new inline template align_ptr() sidesteps this issue as recommended
by the clang-tidy documentation:
  https://clang.llvm.org/extra/clang-tidy/checks/performance-no-int-to-ptr.html

Furthermore, align_ptr() is used to replace this... surprising
piece of code:

    bp += sizeof(align) - (size_t)((uintptr_t)bp % sizeof(align));

See the bug there? When bp is already aligned to a multiple of
sizeof(align), it will overalign! Also, 'align' was a union of a
uint32_t and a char, which is obviously the same alignment of a plain
uint32_t on any architecture ever created!

Bug: 182416023
Change-Id: Id39c3030025e4510feeb55723760a2950067cece
parent 0bff241f
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment