On Sun, 02 Jan 2011 21:04:07 +0100, Walter Bright
<[email protected]> 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).
The false-positive are shown in the presentation ... okey it's was irony,
or not? Better is that:
let is = func[T](state: ref const T, of: val T -> bool):
return !(state & of)
if(is(state=obj.flag, of=MAYBE_THIS_STATE)):
...