This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [Patch, MIPS] Fix warning from malloc/malloc.c
- From: Joseph Myers <joseph at codesourcery dot com>
- To: Carlos O'Donell <carlos at redhat dot com>
- Cc: Steve Ellcey <sellcey at imgtec dot com>, <libc-alpha at sourceware dot org>
- Date: Thu, 11 Dec 2014 14:09:32 +0000
- Subject: Re: [Patch, MIPS] Fix warning from malloc/malloc.c
- Authentication-results: sourceware.org; auth=none
- References: <5b13bf9e-b30c-4405-b2aa-cfa2b3e4c618 at BAMAIL02 dot ba dot imgtec dot org> <5488EFA7 dot 4010604 at redhat dot com>
On Wed, 10 Dec 2014, Carlos O'Donell wrote:
> On 12/10/2014 06:13 PM, Steve Ellcey wrote:
> > Here is a fix for another warning (now error) found in my MIPS build.
> >
> > malloc.c: In function '__posix_memalign':
> > malloc.c:4976:50: error: logical not is only applied to the left hand side of comparison [-Werror=logical-not-parentheses]
> > || !powerof2 (alignment / sizeof (void *)) != 0
> > ^
> > cc1: all warnings being treated as errors
> >
> >
> > The fix is to remove the '!= 0' comparision since it is redundant.
>
> Removing '!= 0' creates a boolean coersion from the int type and we avoid
> this in glibc because it is clearer to say exactly what you mean e.g. != 0 or == 0.
>
> Is not the right fix to add a bracket to clarify the `!` is applied to the left
> side only e.g. "|| (!powerof2 (alignment / sizeof (void *))) != 0"?
The result of "!" is boolean; no implicit boolean conversion is involved
(unless you do "!non_boolean", but then you should write "non_boolean ==
0" not "(!non_boolean) != 0").
--
Joseph S. Myers
joseph@codesourcery.com