NetBSD-Bugs archive

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

Re: lib/37943: posix_memalign doesn't work



The following reply was made to PR lib/37943; it has been noted by GNATS.

From: Michael van Elst <mlelstv%serpens.de@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc: 
Subject: Re: lib/37943: posix_memalign doesn't work
Date: Sun, 3 Feb 2008 06:44:53 +0100

 Hi,
 
 FreeBSD fixed this like:
 
      /* 
 -     * (size & alignment) is enough to assure the requested alignment, since
 +     * (size | alignment) is enough to assure the requested alignment, since
       * the allocator always allocates power-of-two blocks.
       */
      err = errno; /* Protect errno against changes in pubrealloc(). */
 -    result = pubrealloc(NULL, (size & alignment), " in posix_memalign()");
 +    result = pubrealloc(NULL, (size | alignment), " in posix_memalign()");
      errno = err;
 
 but chosing the maximum of size and alignment instead of the bitwise-OR
 should be better in case you allocate power-of-two sized chunks. I.e.:
 
     result = pubrealloc(NULL, size>alignment ? size : alignment, " in 
posix_memalign()");
 
 
 -- 
                                 Michael van Elst
 Internet: mlelstv%serpens.de@localhost
                                 "A potential Snark may lurk in every tree."
 



Home | Main Index | Thread Index | Old Index