静态代码分析工具cppcheck

cppcheck 是一款开源c/ c++ 静态代码分析工具 , 在检测源码时可根据规则就能挖掘出疑似缺陷

下载安装 cppcheck:

http://sourceforge.net/projects/cppcheck/files/

 

有windows和linux版本

下载最新版本cppcheck-1.45.tar.bz2

进入终端

tar -jxvf cppcheck-1.45.tar.bz2

cd cppcheck-1.45

make & make install

安装完成

试验环境  

Linux下使用:
[root@localhost G]# cppcheck -I svnxqjd
cppcheck: No C or C++ source files found.
[root@localhost G]# cppcheck -I svnxqjd/*
Checking svnxqjd/common/common.c...
1/10 files checked 10% done
Checking svnxqjd/config/config.c...
2/10 files checked 20% done
Checking svnxqjd/console/console.c...
3/10 files checked 30% done
Checking svnxqjd/framebuffer/framebuffer.c...
[svnxqjd/framebuffer/framebuffer.c:427]: (error) Resource leak: pfd
[svnxqjd/framebuffer/framebuffer.c:514]: (error) Memory leak: ant
[svnxqjd/framebuffer/framebuffer.c:1165]: (error) Resource leak: pfd
[svnxqjd/framebuffer/framebuffer.c:4968]: (error) Memory leak: ant
[svnxqjd/framebuffer/framebuffer.c:5125]: (error) Memory leak: ant
[svnxqjd/framebuffer/framebuffer.c:5290]: (error) Memory leak: ant
[svnxqjd/framebuffer/framebuffer.c:5340]: (error) Memory leak: ant
[svnxqjd/framebuffer/framebuffer.c:5373]: (error) Memory leak: ant
[svnxqjd/framebuffer/framebuffer.c:5475]: (error) Memory leak: ant
[svnxqjd/framebuffer/framebuffer.c:5628]: (error) Memory leak: ant
[svnxqjd/framebuffer/framebuffer.c:5682]: (error) Memory leak: ant
[svnxqjd/framebuffer/framebuffer.c:5790]: (error) Memory leak: ant
[svnxqjd/framebuffer/framebuffer.c:6143]: (error) Resource leak: pfd
4/10 files checked 40% done
Checking svnxqjd/main/main.c...
5/10 files checked 50% done
Checking svnxqjd/net/net.c...
6/10 files checked 60% done
Checking svnxqjd/service/service.c...
7/10 files checked 70% done
Checking svnxqjd/storage/storage.c...
8/10 files checked 80% done
Checking svnxqjd/touchscreen/touchscreen.c...
9/10 files checked 90% done
Checking svnxqjd/webserver/webserver.c...
10/10 files checked 100% done
[root@localhost G]#

windows下使用:



Example usage:
  # Recursively check the current folder. Print the progress on the screen and
    write errors in a file:
    cppcheck . 2> err.txt
  # Recursively check ../myproject/ and don't print progress:
    cppcheck --quiet ../myproject/
  # Check only files one.cpp and two.cpp and give all information there is:
    cppcheck -v -s one.cpp two.cpp
  # Check f.cpp and search include files from inc1/ and inc2/:
    cppcheck -I inc1/ -I inc2/ f.cpp

For more information:
    http://cppcheck.sf.net/manual.pdf


可以发现内存泄露,变量未使用等等。。。
让我们向完美代码进发。。。

你可能感兴趣的:(windows,linux,ant,工具,leak,代码分析)