From owner-svn-src-all@FreeBSD.ORG Fri Jan 8 20:56:13 2010 Return-Path: Delivered-To: svn-src-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 84533106568B; Fri, 8 Jan 2010 20:56:13 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail04.syd.optusnet.com.au (mail04.syd.optusnet.com.au [211.29.132.185]) by mx1.freebsd.org (Postfix) with ESMTP id 1E44E8FC1B; Fri, 8 Jan 2010 20:56:12 +0000 (UTC) Received: from c122-106-155-90.carlnfd1.nsw.optusnet.com.au (c122-106-155-90.carlnfd1.nsw.optusnet.com.au [122.106.155.90]) by mail04.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id o08KuAjB015357 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 9 Jan 2010 07:56:11 +1100 Date: Sat, 9 Jan 2010 07:56:10 +1100 (EST) From: Bruce Evans X-X-Sender: bde@delplex.bde.org To: Edward Tomasz Napierala In-Reply-To: <201001081544.o08FinVh015359@svn.freebsd.org> Message-ID: <20100109073716.E57804@delplex.bde.org> References: <201001081544.o08FinVh015359@svn.freebsd.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org Subject: Re: svn commit: r201794 - in head/sys: ddb dev/ep dev/ex netinet6 X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Jan 2010 20:56:13 -0000 On Fri, 8 Jan 2010, Edward Tomasz Napierala wrote: > Log: > Replace several instances of 'if (!a & b)' with 'if (!(a &b))' in order > to silence newer GCC versions. I don't like compilers warning about simple logical expressions (especially && vs || and & vs | precedence :-(), but as stefanf pointed out, the reason to change this (or almost anything) is not to silence a broken compiler, but to fix a bug. > Modified: head/sys/ddb/db_ps.c > ============================================================================== > --- head/sys/ddb/db_ps.c Fri Jan 8 15:41:24 2010 (r201793) > +++ head/sys/ddb/db_ps.c Fri Jan 8 15:44:49 2010 (r201794) > @@ -136,7 +136,7 @@ db_ps(db_expr_t addr, boolean_t hasaddr, > if (TD_ON_LOCK(td)) > lflag++; > if (TD_IS_SLEEPING(td)) { > - if (!td->td_flags & TDF_SINTR) > + if (!(td->td_flags & TDF_SINTR)) > dflag++; > else > sflag++; All of these bugs should have been avoided by using normal style. KNF doesn't even use the "!" operator for testing simple booleans! Older KNF code in kern uses comparisions with 0 fairly consistently for testing flags in a bitmap being 0. Even the not-so-old KNF code in kern that tests the not-so-old flag TDF_SINTR does this (there is only one instance, in kern_sig.c, where the above is spelled correctly as ((td->td_flags & TDF_SINTR) == 0). I like to use ! for testing even sets of flags so I prefer the above, but this is not KNF. Spelling for testing the opposite sense is more mixed. Omitting the != 0 seems to be most common. > @@ -171,7 +171,7 @@ db_ps(db_expr_t addr, boolean_t hasaddr, > state[1] = '\0'; > > /* Additional process state flags. */ > - if (!p->p_flag & P_INMEM) > + if (!(p->p_flag & P_INMEM)) > strlcat(state, "W", sizeof(state)); > if (p->p_flag & P_TRACED) > strlcat(state, "X", sizeof(state)); Also spelled correctly in kern (1 instance). Other tests of P_INMEM in kern show the mixed style for putting parentheses around the test for the opposite sense. Then the parentheses are optional and are sometimes omitted in expressions like (p->p_flag & P_INMEM && p->p_pid == pid). Bruce