Less commas

Brad Roberts braddr at puremagic.com
Sun Jan 2 12:59:15 PST 2011


On 1/2/2011 12:56 PM, Peter Alexander wrote:
> On 2/01/11 8:04 PM, Walter Bright wrote:
>> bearophile wrote:
>>> A common bug in Linux kernel:
>>>
>>> if(!state->card->
>>> ac97_status&CENTER_LFE_ON)
>>> val&=~DSP_BIND_CENTER_LFE;
>>>
>>> The fix is to replace (!E & C) with (!(E & C)).
>>>
>>> Currently D acts like C:
>>>
>>> void main() {
>>> uint x, y;
>>> if (!x & y) {}
>>> }
>>>
>>> - 96 instances of this bug in Linux from 2.6.13 (August 2005) to
>>> v2.6.28 (December 2008).
>>> - 58 instances of this bug in 2.6.20 (February 2007)
>>> - 2 in Linux-next (October 10, 2009)
>>>
>>> They have faced and reduced the number of such bugs using Coccinelle,
>>> see pages 8-9 here:
>>> http://coccinelle.lip6.fr/papers/fosdem10.pdf
>>
>> This is great stuff, bearophile. Thanks for finding that. Please add
>> this as an enhancement request to bugzilla (disallowing (!x&y)
>> expressions).
> 
> That really surprises me that it's a common bug. Isn't it obvious that ! has
> higher precedence than &? Or have I totally misunderstood the cause of the bug?

I haven't read the paper, probably should, but is it counting found, fixed,
introduced?  Each of those are different data points.  Also of interest would be
any indicator of total bug counts during that same period.  We're talking about
a LONG period of time here (5-6 years) and a rather large code base that does a
lot of low level bit manipulations.

Later,
Brad



More information about the Digitalmars-d mailing list