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
Loading
Please register or sign in to comment