From: Paul Floyd <pjfloyd@wanadoo.fr>
To: Xi Ruoyao <xry111@xry111.site>,
Alejandro Colomar <alx.manpages@gmail.com>,
GNU C Library <libc-alpha@sourceware.org>
Cc: linux-man@vger.kernel.org
Subject: Re: Issues in manpage memalign
Date: Fri, 10 Mar 2023 08:15:18 +0100 [thread overview]
Message-ID: <36fa486f-1ea4-99f9-0240-4f1691cdbfde@wanadoo.fr> (raw)
In-Reply-To: <99154d24d07cfa550a1ec4f3c5e5f5d222c7fabb.camel@xry111.site>
On 10/03/2023 05:05, Xi Ruoyao wrote:
>
>>> There is a missing EINVAL description. If the alignment is so large that
>>> the allocation will not be possible to satisfy then the call will fail
>>> and set errno to EINVAL.
> POSIX says it should be ENOMEM:
>
> [ENOMEM]
> There is insufficient memory available with the requested alignment.
>
> https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_memalign.html
>
> And it seems also true with Glibc (at least Glibc-2.37):
>
> $ cat t.c
> #include <stdlib.h>
> #include <stdio.h>
>
> int main()
> {
> void *p;
> if (posix_memalign(&p, sizeof(void *) << 55, 1) != 0)
> perror("posix_memalign");
> }
> $ cc t.c
> $ ./a.out
> posix_memalign: Cannot allocate memory
I was referring to memalign / aligned_alloc. The ERRORS section of the
manpage doesn't specify which errors apply to which functions.
Here is an example
#include <stdlib.h>
#include <malloc.h>
int main()
{
void *p;
if ((p == memalign(0xabcdef0123456789, 1)) == 0)
perror("memalign");
}
This does satisfy
EINVAL The alignmentargument was not a power of two, or was not a
multiple of sizeof(void*).
but that is purely a coincidence. The code in gblic that triggers the
error is
│ 3537 /* If the alignment is greater than SIZE_MAX / 2 + 1 it cannot
be a
│ 3538 power of 2 and will cause overflow in the check below. */
│ 3539 if(alignment >SIZE_MAX /2+1)
│ 3540 {
│ > 3541 __set_errno (EINVAL);
│ 3542 return0;
│ 3543 }
If the power-of-two constraint existed this condition would be
redundant. The next power of two greater than SIZE_MAX / 2 + 1 is
SIZE_MAX + 1 which cannot be represented in a word.
Regards
Paul
prev parent reply other threads:[~2023-03-10 7:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <d79b505c-5b19-331c-5b25-d40adc9cc843@wanadoo.fr>
2023-03-10 0:35 ` Alejandro Colomar
2023-03-10 3:02 ` DJ Delorie
2023-03-10 7:21 ` Paul Floyd
2023-03-10 4:05 ` Xi Ruoyao
2023-03-10 7:15 ` Paul Floyd [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=36fa486f-1ea4-99f9-0240-4f1691cdbfde@wanadoo.fr \
--to=pjfloyd@wanadoo.fr \
--cc=alx.manpages@gmail.com \
--cc=libc-alpha@sourceware.org \
--cc=linux-man@vger.kernel.org \
--cc=xry111@xry111.site \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).