Code static analysis tool PC-LINT installation Configuration

Source: Internet
Author: User
Code static analytics tool PC-LINT installation configuration-step by step
Author: ehui928
2006-5-20
PC-Lint is a static analysis tool for C/C ++ software code. You can regard it as a more rigorous compiler. It can not only check common syntax errors, but also identify potential errors that are not easy to detect even if they comply with syntax requirements.
The flexibility of C language increases the code efficiency, but it also leads to the randomness of code writing. In addition, the C compiler does not perform the forced type check, which also brings the risk of code writing. Pclint identifies and reports the occurrence of programming traps and format defects in C language. It performs global analysis of the program, recognizes the array subscript that has not been properly tested, reports uninitialized variables, warns of the use of null pointers, redundant code, and so on. Software Debugging is a major factor in the development cost and delay of software projects. Pclint can help you find encoding errors before dynamic testing of the program. This reduces the cost of eliminating errors.
With PC-lint, you can check code before code reading and unit testing. You can detect program hidden errors in advance, improve code quality, and save test time. It also provides code rule inspection to regulate the coding behavior of software personnel.
Since PC-LINT may be unfamiliar to General programmers, there are many people installed and do not know how to configure and use.
 
The following describes how to install, configure, and use PC-Lint based on my installation and configuration experience. I have introduced how to integrate PC-Lint into VC ++ 6.0 and sourceinsight.

(1) vc6 is widely used in C/C ++ development tools in windows. Therefore, we will first describe how to integrate pclint in the vc6.0 environment.

First of all, of course, you need to download software. The genuine software costs more than $200. You can't afford it! So I had to find a free pull on the Internet. SlaveHttp://www.61ic.com/down/othe/pclint.rarYou can download to a 8.0 version of pclint.

1. Decompress pclint.rar to C:/, so that the lint file is in place with C:/pclint (installation directory.
2. copy the 3 File lib-w32.lnt, env-vc6.lnt, and co-msc60.lnt under C:/pclint/LNT to C:/pclint, and then create STD under the installation directory. LNT and options. two LNT files, STD. the content of LNT is 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

The path after-I is the installation path of VC and the path of VC include file.

Options. LNT content can be empty. It is customized content and will be added later.

After the preparation is complete, the next step is to integrate pclint into vc6. Configure lint to check a single C or C ++ file.

1. Open vc6, tools ---> customize --> tools to create an item named pclint, and enter
Command: C:/pclint/lint-nt.exe
Arguments:-u c:/pclint/STD. lnt c:/pclint/env-vc6.lnt "$ (filepath )"

Use output window check
Close is complete. In this case, A pclint option should be added to the Tools menu in your VC window to run the lint program and perform static checks on your C/C ++ code.

Now we can use a small program to test pclint.

//test1.cpp
#include <string.h>class X{ int *p;public: X() { p = new int[20]; } void init() { memset( p, 20, 'a'  ); } ~X() { delete p; }};

Compile this file to see how many warnings your compiler has given you, and then run lint. You can compare it yourself.
On my machine, VC generates 0 Errors 0 warnings, while the lint program generates the following eight warning messages, some of which are useful. I will not analyze them one by one here.

Test. cpp (12): Error 783: (info -- line does not end with new-line)
Test. cpp (7): Error 1732: (info -- New in constructor for class 'X' which has no assignment operator)
Test. cpp (7): Error 1733: (info -- New in constructor for class 'X' which has no copy constructor)
{Memset (p, 20, 'A ');}
Test. CPP (9): Error 669: (warning -- possible data overrun for function 'memset (void *, Int, unsigned INT) ', argument 3 (size = 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 (11): 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. a vc project usually contains multiple C or C ++ files. Sometimes we need to check the lint of these files at the same time. We can configure a pclint_project to achieve this goal.

The method in the previous step is basically the same, but here we need to use the find and other commands in UNIX to find the C and C ++ files in the current directory, and then send them to the lint program for processing.Http://www.weihenstephan.de /~ Syring/Win32/unxutils.zipDownload unxutils.zip.
Follow these steps:

(Iutildecompress unxutils.zip to C:/Unix, you can see that C:/Unix/usr/local/wbin has many UNIX commands, and will be used later

(Ii) Open vc6, tools ---> customize --> tools to create an item named pclint_project, except that the following commands and arguments have different contents.

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 to check and close and exit. Now there should be another pclint_project item under the VC Tools menu. You can use it to run the lint check program for a VC project.

(2) methods for integrating the pclint program in sourceinsight.

On Windows, many users prefer to use sourceinsight to edit C/C ++ programs. If pclint is integrated into sourceinsight, a C/C ++ compiler is added to sourceinsight, in addition, it checks more strictly, and can find problems that cannot be found by the compiler, which can greatly reduce the latent bugs in the program. In this case, I believe more people will like the sourceinsight tool.

The following describes how to integrate pclint into sourceinsight.

With the experience of integrating pclint in the above VC, the following things should be easier,
(A) Open your sourceinsight, select options --> Custom commands --> Add, and enter pclint (of course, the name can be casual ).

(B) Run input: C:/pclint/lint-NT-U C:/pclint/STD. LNT C:/pclint/env-vc6.lnt % F

(C) Leave dir blank and check the items iconic window, capture output, parse links in output, file, and then line.

(D) click menu ---> menu --> View --> <End of menu> on the right, insert on the right, OK.

(E) A pclint option is added to the View menu in sourceinsight. You can use it to perform static checks on a single C/C ++ file.

You can configure a lint check for a sourceinsight project file in a similar way.

(A) Open your sourceinsight, select options --> Custom commands --> Add, and enter pclint_project (of course, the name can be whatever you like ).

(B) 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) Leave dir blank and check the items iconic window, capture output, parse links in output, file, and then line.

(D) click menu ---> menu --> View --> <End of menu> on the right, insert on the right, OK.

(E) In this case, a pclint_project option is added to the View menu in sourceinsight. You can use it to perform static checks on the C/C ++ file in a project.

This article mainly introduces how to integrate pclint into the VC and sourceinsight environments based on my own installation and usage experiences. I hope that my friends who have never used pclint will be helpful, please correct me for any shortcomings!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.