in /usr/src/lib/libc/stdlib/:

malloc.c:1432:47: warning: & has lower precedence than !=; != will be evaluated 
first [-Wparentheses]
        if (alignment < MALLOC_PAGESIZE || alignment & (alignment - 1) != 0) {
                                                     ^~~~~~~~~~~~~~~~~~~~~~

This is in mapalign(), which is only called from omemalign(), which is only
called from posix_memalign(), which already does this check.

The check for alignment < MALLOC_PAGESIZE is done in omemalign(), so maybe
the whole if is redundant.

Here is a diff that fixes the check and unifies its style with the check in
posix_memalign():

Index: malloc.c
===================================================================
RCS file: /cvs/src/lib/libc/stdlib/malloc.c,v
retrieving revision 1.146
diff -u -p -r1.146 malloc.c
--- malloc.c    9 Jul 2012 08:39:24 -0000       1.146
+++ malloc.c    13 Sep 2012 09:47:02 -0000
@@ -1429,7 +1429,7 @@ mapalign(struct dir_info *d, size_t alig
 {
        void *p, *q;
 
-       if (alignment < MALLOC_PAGESIZE || alignment & (alignment - 1) != 0) {
+       if (alignment < MALLOC_PAGESIZE || ((alignment - 1) & alignment) != 0) {
                wrterror("mapalign bad alignment", NULL);
                return MAP_FAILED;
        }


-- 
Michal Mazurek

Reply via email to