https://bugs.kde.org/show_bug.cgi?id=509107

--- Comment #2 from Paul Floyd <[email protected]> ---
I was just looking at this. On older libcs aligned_alloc is just a weak alias
for memalign

000000000009c030 T __libc_memalign@@GLIBC_2.2.5
000000000009c030 W aligned_alloc@@GLIBC_2.16
000000000009c030 W memalign@@GLIBC_2.2.5

The man page claims that the alignment value must be a power of two but in fact
libc secretly rounds it up to the next power of two and does not complain.
Tools that replace malloc on Linux still have this strange behaviour (but with
an error message). The man page also says that aligned_alloc has a further
restriction that size must be a multiple of alignemnt. Again due to the alias
that was not true. Newer libcs have a separate aligned_alloc that respects the
man page. In Valgrind, we redirect both memalign and aligned_alloc, but with a
weak alias it is the last one that gets kept. And that is memalign.

And now that I look at the error it strikes me as inconsistent. I was probably
thinking too much of these alias issues. 

There are 2 things that I think I should do
1. Change the message to be "Invalid size value : 0 (should be ...)"
2. Add a 'memalign' expected.

I don't think that AddressSanitizer does a very good job here either. It
doesn't complain about the operator new with an alignment of zero and it
performs an allocation (but without ASAN libstdc++ returns a NULL pointer).

The ASAN message for the first aligned_alloc (and note that ASAN, with compile
time instrumentation, redirects aligned_alloc not memalign) is

==4125927==ERROR: AddressSanitizer: invalid alignment requested in
aligned_alloc: 64, alignment must be a power of two and the requested size 0x64
must be a multiple of alignment (thread T0)

I really don't like that mixing of decimal alignment and hex size.

There's no way with ASAN to see all the errors. It exists at the first error
and says HINT: if you don't care about these errors you may set
allocator_may_return_null=1 which turns off all these kinds of errors.

ASAN doesn't complain about memalign/aligned_alloc size of zero.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to