public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dave Jones <davej@redhat.com>
To: John Levon <levon@movementarian.org>
Cc: Linux Kernel list <linux-kernel@vger.kernel.org>
Subject: Re: logic error in radeonfb.
Date: Fri, 23 Jan 2004 13:53:44 +0000	[thread overview]
Message-ID: <20040123135343.GI9327@redhat.com> (raw)
In-Reply-To: <20040123112444.GB81582@compsoc.man.ac.uk>

On Fri, Jan 23, 2004 at 11:24:44AM +0000, John Levon wrote:

 > > Back then someone came up with a cool one-liner that grepped for
 > > suspicious if's with !'s, it seems no-one ever did the same for 2.6,
 > > as there were a few others (see seperate mails for patches).
 > 
 > Actually I did make a one-liner for 2.6, and found rather a lot (15 or
 > so if I remember correctly). I also went as far as hacking up something
 > in gcc, but it was too flaky to go in and I haven't got round to fixing
 > it up yet.
 > 
 > Some of them were right under our noses for ages:
 > http://linus.bkbits.net:8080/linux-2.5/user=levon/patch@1.889.272.4?nav=!-|index.html|stats|!+|index.html|ChangeSet|cset@1.889.272.4
 > If you like I can see if I can dig up the gcc patch or the one-liner.

Yep, that's where I got the idea for this (seems no-one did the
same for the 2.6 tree). Here's the one-liner..
 
find ${1:-.} -name "*.c"    -type f | xargs grep -En '![a-zA-Z0-9_ ]+(\|[^|]|\&[^&])|([^|]\||[^&]\&) *!' | grep -v SCCS

As well as the misplaced brackets, it also catches if (foo & bar) where && was
probably intended (ditto | instead of ||).
It does miss some cases though. Whereas this..

find ${1:-.} -name "*.c"    -type f | xargs grep -En 'if[\ ]\(' | grep -v SCCS | grep \)[\ ]\[\|\&][\ ]  

turns up a few more, but also a lot more false positives.

And if you think the number of bugs it turned up in the kernel is
unfunny, you should see the results when you run it on a source tree
of an unpacked distro. It's Un-be-lievable how common this problem is.
It's not every week you get to do patches to ~80 projects in 3 days 8-)

I tried coming up with some regexps for other 'stupid errors',
things like
	if (foo);
		bar 

or the likes, I got 1-2 real hits out of zillions of lines of code
as opposed to the few dozen misplaced brackets and '|' instead of '||'

Fun.

		Dave


      reply	other threads:[~2004-01-23 13:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-23  6:35 logic error in radeonfb davej
2004-01-23  6:46 ` Benjamin Herrenschmidt
2004-01-23  6:54   ` Dave Jones
2004-01-23  7:03     ` Benjamin Herrenschmidt
2004-01-23 11:24     ` John Levon
2004-01-23 13:53       ` Dave Jones [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040123135343.GI9327@redhat.com \
    --to=davej@redhat.com \
    --cc=levon@movementarian.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox