bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: posix_memalign() bug in glibc-2.2.5?


From: Andreas Jaeger
Subject: Re: posix_memalign() bug in glibc-2.2.5?
Date: Sun, 09 Jun 2002 12:51:43 +0200
User-agent: Gnus/5.090007 (Oort Gnus v0.07) XEmacs/21.4 (Artificial Intelligence, i386-suse-linux)

Alceste Scalas <address@hidden> writes:

> 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?  ?:-\

No, you arent't.

>
> Regards, and keep up the good work,


Fixed already in our CVS version:

      * malloc/malloc.c (__posix_memalign): Correct check for size of
        alignment value [PR libc/3444].

Thanks for the report,
Andreas
-- 
 Andreas Jaeger
  SuSE Labs address@hidden
   private address@hidden
    http://www.suse.de/~aj



reply via email to

[Prev in Thread] Current Thread [Next in Thread]