Hi,
On Tue, Sep 20, 2005 at 04:49:49PM +0900, Mike McCormack wrote:
Found with:
find . -name *.c -exec grep "if *([^)]*); *" {} ; -ls
Could you perhaps create a first version of a shell script tools/find_gotchas ?
We really need to make sure all those many things similar to this get fixed on an ongoing basis.
Other gotchas could be
if (a = b) (not easily identifiable since it might be legitimate, though)
HFILE x = 0; (instead of INVALID_HANDLE or so)
Andreas Mohr
Andreas Mohr wrote:
Could you perhaps create a first version of a shell script tools/find_gotchas ?
I have other things to do at the moment, so go ahead if you're feeling motivated. I suspect you'll run into alot of false positives. There might be a compiler switch to turn on warnings for these things too (ie. statements with no effect).
Mike
Mike McCormack wrote:
Andreas Mohr wrote:
Could you perhaps create a first version of a shell script tools/find_gotchas ?
I have other things to do at the moment, so go ahead if you're feeling motivated. I suspect you'll run into alot of false positives. There might be a compiler switch to turn on warnings for these things too (ie. statements with no effect).
Gcc-4.0 catches this:
erikd@miles > cat test.c int main (void) { if (0) ; return 0 ; } erikd@miles > gcc-4.0 -W -Wall test.c -o /dev/null test.c: In function 'main': test.c:3: warning: empty body in an if-statement
Erik
Erik de Castro Lopo wrote:
Gcc-4.0 catches this:
erikd@miles > cat test.c int main (void) { if (0) ; return 0 ; } erikd@miles > gcc-4.0 -W -Wall test.c -o /dev/null test.c: In function 'main': test.c:3: warning: empty body in an if-statement
Yes, but only if you use -W -Wall, which wine unfortunately doesn't :/
bash-3.00$ cat > t.c int boo(int arg) { if (arg); return 0; } bash-3.00$ /usr/local/gcc-4.0.1/bin/gcc -c -Wall t.c bash-3.00$ /usr/local/gcc-4.0.1/bin/gcc -c -W -Wall t.c t.c: In function 'boo': t.c:2: warning: empty body in an if-statement
Mike
Mike McCormack wrote:
Erik de Castro Lopo wrote:
Gcc-4.0 catches this:
erikd@miles > cat test.c int main (void) { if (0) ; return 0 ; } erikd@miles > gcc-4.0 -W -Wall test.c -o /dev/null test.c: In function 'main': test.c:3: warning: empty body in an if-statement
Yes, but only if you use -W -Wall, which wine unfortunately doesn't :/
Properly documented (in the janitorial part on the wiki) this is good enough. No need to write an extra tool/script to catch those if problems. I once wrote a script for smatch to look for such cases but i'm not sure i finished it or at least it's not part of the standard smatch scripts I run.
bash-3.00$ cat > t.c int boo(int arg) { if (arg); return 0; } bash-3.00$ /usr/local/gcc-4.0.1/bin/gcc -c -Wall t.c bash-3.00$ /usr/local/gcc-4.0.1/bin/gcc -c -W -Wall t.c t.c: In function 'boo': t.c:2: warning: empty body in an if-statement
bye michael