[valgrind] [Bug 446754] Improve error codes from alloc functions under memcheck

2022-05-09 Thread Paul Floyd
https://bugs.kde.org/show_bug.cgi?id=446754

Paul Floyd  changed:

   What|Removed |Added

 Status|REPORTED|RESOLVED
 Resolution|--- |FIXED

--- Comment #6 from Paul Floyd  ---
I pushed the changes, but only for FreeBSD and Solaris.

I'll leave the Linux decision to Mark.

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

[valgrind] [Bug 446754] Improve error codes from alloc functions under memcheck

2021-12-10 Thread Paul Floyd
https://bugs.kde.org/show_bug.cgi?id=446754

--- Comment #1 from Paul Floyd  ---
On Linux aligned_alloc accepts an alignment of 0 and an alignment of 40 (i.e., 
not a power of 2). So the man page is wrong. In fact everything that the man
page says about errors concerning alignment/size is wrong.

Looking here

https://elixir.bootlin.com/glibc/latest/source/malloc/malloc.c#L3416

If the alignment is less than MALLOC_ALIGNMENT (which is 16 for i386 and the
max(2*sizeof(size_t), sizeof(long double)) on other platforms) then it just
calls the malloc implementation, no error.

Not in the man page but in the source there is a check that alignment is not
over half the max value of size_t. That causes EINVAL.

Lastly if the alignment is not a power of 2 it gets bumped up to the next power
of 2, no error.

There is no check that size is a multiple of alignment.

What a nightmare.

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

[valgrind] [Bug 446754] Improve error codes from alloc functions under memcheck

2021-12-10 Thread Tom Hughes
https://bugs.kde.org/show_bug.cgi?id=446754

Tom Hughes  changed:

   What|Removed |Added

 CC||t...@compton.nu

--- Comment #2 from Tom Hughes  ---
I think that's only true for memalign (which the manual page says is obsolete)
and aligned_alloc (which appears to be an alias for memalign even the manual
page says it has an extra restriction) though, and posix_memalign does enforce
power of two and a multiple of sizeof(void *) as the manual page says:

https://elixir.bootlin.com/glibc/latest/source/malloc/malloc.c#L5553

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

[valgrind] [Bug 446754] Improve error codes from alloc functions under memcheck

2021-12-10 Thread Paul Floyd
https://bugs.kde.org/show_bug.cgi?id=446754

--- Comment #3 from Paul Floyd  ---
Yes, posix_memalign looks a lot better.

For aligned_alloc I need to dig through the jemalloc code (used on FreeBSD).
It's much more factorized which makes it fairly hard to follow.

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

[valgrind] [Bug 446754] Improve error codes from alloc functions under memcheck

2021-12-11 Thread Paul Floyd
https://bugs.kde.org/show_bug.cgi?id=446754

--- Comment #4 from Paul Floyd  ---
Created attachment 144458
  --> https://bugs.kde.org/attachment.cgi?id=144458&action=edit
Updated patch

Added as much as possible to the comment and added Solaris.

The big question is should I keep the conditon that size % align == 0 ? The man
pages seem to say it is not allowed / UB but none complain or set EINVAL.

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

[valgrind] [Bug 446754] Improve error codes from alloc functions under memcheck

2021-12-11 Thread Paul Floyd
https://bugs.kde.org/show_bug.cgi?id=446754

--- Comment #5 from Paul Floyd  ---
Also either we need to make the same checks in memalign as in aligned_alloc or
else disable the aligned_alloc tests for Linux in the testcase

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