code static analysis tool pc-lint installation configuration--step by step
ehui928
2006-5-20
pc-lint is a static analysis tool for C/s + + software code, you can think of it as a more rigorous compiler. Not only can it check for general syntax errors, but it can also check out potential errors that are not easily discoverable, although they are grammatically demanding. The flexibility of the
c language leads to the increase of code efficiency, but it brings the randomness of code writing, and the C compiler does not enforce type checking, but also brings the hidden trouble of code writing. Pclint identifies and reports on the occurrence of programming traps and formatting defects in the C language. It carries out a global analysis of the program, identifies array subscripts that are not properly inspected, reports uninitialized variables, warns about using null pointers, redundant code, and so on. Software debugging is a major factor in the cost and delay of software project development. Pclint can help you find coding errors before the program is dynamically tested. This eliminates errors at a lower cost.
Use Pc-lint to check for code day and unit tests before you can discover program hiding errors, improve code quality, and save test time. and provide the code rules check, standardize the code behavior of software personnel.
because Pc-lint may be unfamiliar to the general programmer, there are many people who have installed and don't know how to configure and use it.
The following is a detailed description of the installation, configuration and use of pc-lint based on my own installation and configuration experience. I mainly introduce the methods and steps of integrating Pc-lint into vc++6.0 and sourceinsight.
A VC6 use is more common in Windows/C + + development tools, so here are the steps to integrate pclint in the VC6.0 environment first.
first of all, of course to download software, genuine software to more than 200 $ it, can not afford! So I had to find free pull on the internet. From http://www.61ic.com/down/othe/pclint.rar You can download to a version 8.0 of Pclint.
1. Unzip the Pclint.rar to c:/so that the lint file is in place with the C:/pclint (installation directory).
2. Copy the 3 files under C:/pclint/lnt lib-w32.lnt,env-vc6.lnt,co-msc60.lnt to C:/pclint, Then create the STD.LNT and options.lnt two files in the installation directory, where the contents of STD.LNT are as follows
Contents of STD.LNT
C:/pclint/co-msc60.lnt
C:/pclint/lib-w32.lnt
C:/pclint/options.lnt-si4-sp4
-I "D:/program files;d:/program files/microsoft Visual studio/vc98/include"
End
Where-I followed by the path named VC installation path and VC Include file path, according to their own modifications can be.
OPTIONS.LNT content can be empty, for custom content, and then added later if needed.
When the preparation is done, the next step is to integrate the pclint into the VC6, first configuring the lint so that it can be checked against a single C or C + + file.
1. Open Vc6,tools--->customize-->tools create a new entry named Pclint, fill in the following
Command:c:/pclint/lint-nt.exe
Arguments:-u c:/pclint/std.lnt c:/pclint/env-vc6.lnt "$ (FilePath)"
Use the Output Window tick
Close is complete. This should be a pclint option under your VC window Tools menu, you can use it to run the lint program, and to do a static check on your C + + code.
Now we can test the pclint with a small program.
Test1.cpp
#include <string.h>class X {int *p; Public : X () { p = new int[+];} voidInit () { memset( p, b, ' a ' ) ); } ~X () { delete p ; }};
Compile this file, see how many warnings your compiler has given you, and then run the next lint to compare yourself.
On my machine, VC generated 0 errors 0 warnings, and lint program produced the following 8 warning messages, some are very useful tips, here is not analyzed.
Test.cpp: Error 783: (Info--line does not end with New-line)
Test.cpp (7): Error 1732: (Info--New in constructor for class ' X ' which have no assignment operator)
Test.cpp (7): Error 1733: (Info--New in constructor for class ' X ' which have no copy constructor)
{memset (p, B, ' a ');}
Test.cpp (9): Error 669: (Warning--Possible data overrun for function ' memset (void *, int, unsigned int) ', Argument 3 (SI ze=97) exceeds argument 1 (size=80) [Reference:test.cpp:lines 7, 9])
Test.cpp (7): Error 831: (Info--Reference cited in prior message)
Test.cpp (9): Error 831: (Info--Reference cited in prior message)
{delete p;}
Test.cpp (one): Error 424: (Warning--inappropriate deallocation (delete) for ' new[] ' data)
---wrap-up for Module:test.cpp
Test.cpp (2): Error 753: (Info--local class ' X ' (line 2, file test.cpp) not referenced)
Tool returned Code:8
2. Usually a VC project contains multiple C or C + + files, sometimes need to lint this series of files at the same time, we can configure a pclint_project to achieve the goal.
and the first step in the previous method is basically the same, but here we need to use the Unix find and other commands to find the current directory of C and C + + files, and then send them to the Lint program processing, so we have to first from Http://www.weihenstephan.de/~syring/win32/UnxUtils.zip download Unxutils.zip.
Then follow the steps below:
(i) Decompression unxutils.zip to C:/unix, you can see C:/unix/usr/local/wbin have a lot of UNIX commands, and so will use
(ii) Open Vc6,tools--->customize-->tools a new item named Pclint_project, except for the commands and arguments content below.
Commands:c:/unix/usr/local/wbin/find.exe
Arguments: $ (filedir)-name *.c-o-name *.cpp | C:/unix/usr/local/wbin/xargs lint-nt-i "C:/unix/usr/local"-u c:/pclint/std.lnt c:/pclint/env-vc6.lnt
(iii) Use Output window tick, close exits. OK, then VC Tools menu should have another Pclint_project item, you can later use it to a VC project run lint check the program.
Two Methods for integrating Pclint programs in Sourceinsight.
There are a lot of people under the Windows platform who like to use the Sourceinsight to edit C + + programs, if the Pclint integration into Sourceinsight, it is equivalent to the sourceinsight added a C + + compiler, And it's more stringent inspection, can find some compiler can not find the problem, could greatly reduce the latent bug in the program. In this case, believe that more people will like sourceinsight this tool.
The following is a brief introduction to the method of Pclint integration into Sourceinsight
With the above VC integration Pclint experience, the following things should be more relaxed,
(a) Open your sourceinsight, choose Options-->custom commands-->add, enter Pclint (of course, the name can be casual).
(b) Enter in run: C:/pclint/lint-nt-u c:/pclint/std.lnt c:/pclint/env-vc6.lnt%f
(c) Dir is left blank, iconic window, Capture output, Parse Links in Output, File,then line four before tick.
(d) Then click on the right Menu--->menu-->view--><end of menu>, right insert, OK.
(e) A pclint option is now available under the View menu in Sourceinsight, which allows you to perform a static check of a single C + + file.
A similar approach can be used to configure a lint check of a sourceinsight project file.
(a) Open your sourceinsight, choose Options-->custom commands-->add, enter Pclint_project (of course, the name can be casual).
(b) input in run: C:/unix/usr/local/wbin/find.exe%d-name *.c-o-name *.cpp | C:/unix/usr/local/wbin/xargs lint-nt
-I "c:/unix/usr/local"-u c:/pclint/std.lnt c:/pclint/env-vc6.lnt
(c) Dir is left blank, iconic window, Capture output, Parse Links in Output, File,then line four before tick.
(d) Then click on the right Menu--->menu-->view--><end of menu>, right insert, OK.
(e) A pclint_project option is available under the View menu in Sourceinsight, which can be used to perform a static check on a C/D + + file in a project.
This article mainly on the Pclint integrated into the VC and sourceinsight environment of the method according to my installation and use of experience to do a more detailed introduction, I hope to have not used before pclint friends can help, the shortcomings of the more please correct!
http://blog.csdn.net/adcxf/article/details/2065722
Code Static analysis tool Pc-lint installation configuration