[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
posix_memalign() bug in glibc-2.2.5?
From: |
Alceste Scalas |
Subject: |
posix_memalign() bug in glibc-2.2.5? |
Date: |
Sun, 9 Jun 2002 12:31:59 +0200 |
User-agent: |
Mutt/1.4i |
Hello,
I think that there is something strange in the glibc-2.2.5 (at
least) implementation of posix_memalign(). The glibc info pages
say:
| - Function: int posix_memalign (void **MEMPTR, size_t ALIGNMENT,
| size_t SIZE)
|
| The `posix_memalign' function is similar to the `memalign'
| function in that it returns a buffer of SIZE bytes aligned to
| a multiple of ALIGNMENT. But it adds one requirement to the
| parameter ALIGNMENT: the value must be a power of two multiple
| of `sizeof (void *)'.
It is in accordance with the POSIX standard requirements.
However, the function implementation is quite different:
| int
| __posix_memalign (void **memptr, size_t alignment, size_t size)
| {
| void *mem;
|
| /* Test whether the SIZE argument is valid. It must be a power of
| two multiple of sizeof (void *). */
| if (size % sizeof (void *) != 0 || (size & (size - 1)) != 0)
| return EINVAL;
|
| mem = __libc_memalign (alignment, size);
|
| if (mem != NULL)
| {
| *memptr = mem;
| return 0;
| }
|
| return ENOMEM;
| }
| weak_alias (__posix_memalign, posix_memalign)
The dimension check is performed on the "size" parameter, while it
should be done on "alignment".
It both violates the POSIX standard, and creates a number of
problems (allocated memory must be a multiple of sizeof(void*) and a
power of 2, with obvious memory wasting issues).
Am I wrong? ?:-\
Regards, and keep up the good work,
alceste
--
This .signature is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option)
any later version. ___________________________________
______________________________________) PGP information in e-mail header |
pgprPX2ze7hng.pgp
Description: PGP signature
- posix_memalign() bug in glibc-2.2.5?,
Alceste Scalas <=