Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Installation of PC-Lint and its using in Visual Studio 2005


Published on

The article is devoted to the first acquaintance with the PC-Lint 8.0 static analyzer of C++ code. The process of the tool installation and its initial setting is described.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Installation of PC-Lint and its using in Visual Studio 2005

  1. 1. Installation of PC-Lint and its using inVisual Studio 2005Author: Andrey KarpovDate: 23.12.2008AbstractThe article is devoted to the first acquaintance with the PC-Lint 8.0 static analyzer of C++ code. Theprocess of the tool installation and its initial setting is described.IntroductionC++ language is one of the most powerful but at the same time one of the most difficult programminglanguages. Countless amount of literature is written about creating a high-quality code, using differentmethodologies of development and testing. But the problem of increasing the quality of developingcode is still an actual sphere, which is not entirely studied.Among the tools that help in testing and upgrading the program code it is possible to point out severalclasses.The systems for automating unit-testing can be referred to the fist class. Such well-known program toolsas AutomatedQA TestComplete ( or Parasoft Jtest( can be given as examples. This testing methodology is applied in manycompanies with great success and is irreplaceable in case of working at a dynamically developingprogram product.The other direction is reducing the costs of the software testing stage is identification of the changedsoftware parts. This helps to considerably reduce the amount of manual testing and to point out themodified areas for a more careful checking. This approach supports high testing quality at less timeexpense. The representative of this tool class is Testing Relief ( debugging of large applications the dynamic analyzers proved good. Valgrind( and Compuware BoundsChecker ( may be referredthere.A wide range of tasks of program code checking is solved by static analyzers of both general and specific.To the first, for example, can be referred the production of Coverity Incorporated company( or Gimpel Software PC-Lint (, which we willdescribe more carefully. To the specific static analyzers we can refer Viva64 tool( ) aimed for detect 64-bit portability issues and errors.In this article the first steps are considered of the studying static analyzer Gimpel Software PC-Lint 8.0version. It is connected with its popularity among developers of software and their interest in usingsimilar static analyzers. Using static code analyzers has become culture in many large companies longago and the interest to such tools is constantly increasing.
  2. 2. 1. PC-Lint InstallationAt the first acquaintance of a beginning user with PC-lint some difficulties may arouse in understandingthe principles of work of this program and its settings. Having accomplished the recommendations givenin this article you can get down to the code analysis proper quicker and not waist time on studying thepeculiarities of settings at the first stages of work.This article on installing and setting PC-lint will be represented as a simple manual consisting of pictureswhich show different steps and an explanation text to them.
  3. 3. Picture 1. Run setup wizard.Picture 2. Look through the first pages of setup wizard.
  4. 4. Picture 3. Agree with the license agreement.
  5. 5. Picture 4. Input your name and the name of the organization.
  6. 6. Picture 5. Choosing the directory for the installation. For you will have to work with the folder where PC-lint is installed quite often, we do not recommend you to install it in a directory that is more than onelevel from a root directory to correct the configuration file or read the documentation. On the otherhand, after installing you will be able to configure necessary links to the files you are interested in, andthen the file location is of no importance. We agree for the installation in the root catalogue of disc C.
  7. 7. Picture 6. Continue the process of installation.
  8. 8. Picture 7. When the installation is finished, agree with the running of the configuration program.
  9. 9. Picture 8. Now its time to make coffee and get ready for the setting your new tool.
  10. 10. Picture 9. PC-lint makes it possible to use itself standalone in a batch mode. But in our opinion moreconvenient is its interactive using from Visual Studio sphere. The description of integration process of
  11. 11. PC-lint into the sphere you can find in env-vc7.lnt file. This file contains information on integration intoVisual Studio 2003, but the difference in the integration into Visual Studio 2005 is not much noticeable.You may not address this file but use our document, where all the necessary corrections concerningVisual Studio 2005 have already been done.2. Primary Setting
  12. 12. Picture 10. Choosing the location of the configuration file, which is going to be created by the wizard.We recommend to put it in the same place with PC-lint for all the files referring to this utility to belocated in the same place. In the opposite case you will have to waste some more time on path settingsto different files. You can also use the existing configuration file. Let us choose creating of newconfiguration file.
  13. 13. Picture 11. Choose a more appropriate configuration file for our compiler. Unfortunately, we will notfind Visual C++ 2005 in the list, so we stop at Visual C++ 2003. Further on we will manually correct theconfiguration file "STD.LNT" generated by the setup wizard.
  14. 14. Picture 12. Choosing the database we are interested in.
  15. 15. Picture 13. We will evidently need the support of MFC, STL and Win32API libraries, so we include thecorresponding configuration files. This setting does a very important thing: it copies LNT files necessaryfor work from "C:Lintlnt" catalogue into "C:Lint" catalogue. Otherwise you will have to do it manually.These files will not be found in "C:Lintlnt" catalogue even if you add this directory to the pathenvironment.
  16. 16. Picture 14. It is for you to decide what to choose from the list of different sets of rules of codeverification. For now you may choose nothing, and then manually or with the help of the same wizard toadd or remove different sets analyzing then the result of verification on your programs.
  17. 17. Picture 15. If you use in your program not only standard include files but also external libraries (forexample, Mesa), then you will have to write the corresponding paths.
  18. 18. Picture 16. Writhe the paths to the necessary include files. It is strongly recommended to be done,otherwise PC-lint will simply stop at the lines #include "unknown.h".
  19. 19. Picture 17. Thats it, the creating of the base configuration file is over.Picture 18. Now we can, using it as an example, make configuration files we need. We will not createother configurations, thats why we choose "No".
  20. 20. Picture 19. We can also execute some additional settings on PC lint behavior. Now we will pass through PC-lintthis stage to demonstrate further on the connection between these settings with the "options.lnt"configuration file.Picture 20. We will not describe further settings in detail. It will be up to you to decide what to considerto be a suspicious code and what not. But we would like to say that we decided not to consider thefollowing construction suspicious:if ( (a = b) ) { ...}
  21. 21. Picture 21. Choose more appropriate settings for our environment. Choosing "env-vc7.lnt" is notreflected on generated configuration files. The sense of this setting is not clear. A mistake possibly existsin the master of configuration. We will later add "env-vc7.lnt" into the configuration ourselves.
  22. 22. Picture 22. For we are not going to use PC-lint in a batch mode, we can skip this step of configuration.
  23. 23. Picture 23. The installation of the utility is finished completely, now it is possible to get down to the finalsetting and integration into Visual Studio 2005.In the beginning we need to go to the site and get new updates for PC-lint andnew configuration files. As we use 8.00 version, we download the updates for it from the page you do not have "co-msc80.lnt" file, then get it. It is represented as a configuration file for working inVisual Studio 2005. In any case it must be placed in the folder "C:Lint" (see also picture 10).You may also see other updates and do what you think is necessary.Now we are ready to get down to completion of configuration files. First of all let us look at the files,which were generated during the installation of PC-lint utility. These are the files "options.lnt" and"std.lnt". Let us start with the file "options.lnt". It looks like the following:// Please note -- this is a representative set of error suppression// options. Please adjust to suit your own policies// See manual (chapter LIVING WITH LINT)// for further details.-e820 // allow test of parenthesized assignmentIn this file the wizard saved our wishes concerning the analysis of some situations (see picture 15). Doyou remember we decided that the construction of the kindif ( (a = b) ) { ...}correct? The result of this solution will be reflected in the file "options.lnt" as a line-e820 // allow test of parenthesized assignmentwhich says to consider these constructions safe.The file "options.lnt" is included in "std.lnt". The ideology of the including of one PC-lint configurationfile into another is the same as the ideology of using the file "#include" in C/C++ languages.Now let us have a look at the file "std.lnt"// Microsoft Visual C++ .NET 2003,// -si4 -sl4 -sp8, lib-mfc.lnt lib-stl.lnt lib-w32.lnt// Standard lint optionsco-msc71.lnt
  24. 24. lib-mfc.lnt lib-stl.lnt lib-w32.lntoptions.lnt -si4 -sl4 -sp8-iD:ASRCfox-libfox-1.4.4include-iD:ASRCLibrariesmesaincludeThe line "co-msc71.lnt" includes (like #include in C/C++) the setups for Visual C++ compiler in our mainconfiguration file. Change this line into "co-msc80.lnt" at once.The line "lib-mfc.lnt lib-stl.lnt lib-w32.lnt" can be left without changes.Let us add "env-vc7.lnt". We do not have the file "env-vc8.lnt" but everything will work perfectly wellwith "env-vc7.lnt". It is suggested not to include "env-vc7.lnt" in your configuration files in thedocumentation to PC-lint but to use it as one of the parameters at the call from the MSVC environment.But to our mind it is more convenient that all the settings should stay at the same place. Anyway"std.lnt" is already oriented to the work in Visual Studio environment. And when, for example, "env-vc8.lnt" appears, it is easier to correct in one place (in "std.lnt") than to correct several commands inVisual Studio environment, which call PC-lint.The line "options.lnt -si4 -sl4 -sp8" seems to be difficult, but in fact four simple and independent keys ofsetting are located in it. The first on includes "options.lnt" into the file "std.lnt". The rest serve to setsizing of data types. You should see the documentation, which is included in the PC-lint set, for thedetails.The idea of using the included files is very convenient. It is possible to collect separately path settings tothe headline files or to include/exclude a number of warnings. And then to build the final configurationfiles with them like with the bricks. We suppose that you will cope with it quite easily yourselves. Nowlet us get rid of the file "options.lnt" to make it simpler having transferred its contents in "std.lnt".Let us add one more level of warnings to configurations, which is set with the key -w##.After the corrections the file "std.lnt" looks the following way:-iD:ASRCfox-libfox-1.4.4include-iD:ASRCLibrariesmesaincludeco-msc80.lntenv-vc7.lntlib-mfc.lntlib-stl.lntlib-w32.lnt-si4 -sl4 -sp8-w3-e820
  25. 25. It is quite a working variant of the configuration, and its time to integrate PC-lint into MSVC PC-environment.3. Integration into Visual Studio 2005
  26. 26. Picture 24. Let us start Visual Studio 2005 and get down to PC-lint integration. We are going to create linttree new options in Tools menu:Project Creation is the creation of PC lint project for verification of all files in MSVC project; PC-lintProject Check the verification according to the earlier created project (verification of all the files); (verificationUnit Check is the verification of the current file;In the documentation to PC-lint using the operation called "Simple Check" for the verification of a lintseparate unit of the compilation. But in practice one can rarely run across independent modules.
  27. 27. Picture 25. Choose the option "External Tools ..." in Tools menu.
  28. 28. Picture 26. Push the button "Add".
  29. 29. Picture 27. Let us fill in the corresponding fields like it is shown in the picture.Picture28. Push the button OK. And now we can see the option "PC-lint (Project Creation)" in "Tools"menu.
  30. 30. Picture 29. Now we are going to create the option "Project Check" like we did with the "ProjectCreation". We will have to repeat all the previous steps for it but we are going to fill in the fields inanother way (pay attention to check boxes).
  31. 31. Picture 30. The last command is "Unit Check". All those steps are made to create it.
  32. 32. Picture 31. If you want to check if you hade done everything correctly, then in the "Tools" menu you cansee three new options. Here the integration of PC-lint in Visual Studio is finished.If you want to check all your project, you will have to use the option PC-lint (Project Creation) first andthen PC-lint (Project Check).
  33. 33. You must use PC-lint (Project Creation) again when you add or delete files from the project or modify ntthe settings of the project.PC-lint (Unit Check) serves for the code verification in the active window. It is convenient while writing lintnew code. Take into consideration th you will have to execute PC-lint (Project Creation) first to use PC that lint PC-lint (Unit Check).Picture 32. Now praise yourself with one more cup of coffee for the work done and we will assay thisnew utility.
  34. 34. Picture 33. Create a simple Win32 console application.
  35. 35. Picture 34. We need the simplest application, thats why we push the button "Finish".Write the following program. Let us get assured that the program compiles, and the compiler does notgive out warnings even at the fourth level (/W4). en#include "stdafx.h"TCHAR FooTxt[] = _T("foo");bool Foo(int argc, _TCHAR* argv[]){ for (int i = 0; i != argc; ++i) { if (_tcscmp(argv[i], FooTxt) == 0) { return true; } } return false;}int _tmain(int argc, _TCHAR* argv[]) int{ if (Foo(argc, argv))
  36. 36. return 1; return 0;}No its timeto use PC-lint. First we execute "PC-lint (Project Creation)", and then "PC-lint (ProjectCheck)". If everything is set correctly, you must get approximately the following conclusion:PC-lint for C/C++ (NT) Vers. 8.00u, Copyright Gimpel Software 1985-2006--- Module: .SimpleProjectForPClint.cpp (C++)}.SimpleProjectForPClint.cpp(14): error 818: (Info -- Pointer parameter argv (line 5) could be declaredas pointing to const).SimpleProjectForPClint.cpp(5): error 830: (Info -- Location cited in prior message)--- Module: .stdafx.cpp (C++)--- Wrap-up for Module: .stdafx.cpp.stdafx.cpp(9): error 766: (Info -- Header fileD:WORK3SimpleProjectForPClintSimpleProjectForPClintstdafx.h not used in module .stdafx.cpp)--- Global Wrap-up.SimpleProjectForPClint.cpp(5): error 765: (Info -- external Foo(int, unsigned short **) (line 5, file.SimpleProjectForPClint.cpp) could be made static).SimpleProjectForPClint.cpp(3): error 765: (Info -- external FooTxt (line 3, file.SimpleProjectForPClint.cpp) could be made static) D:WORK3SimpleProjectForPClintSimpleProjectForPClintstdafx.h(9): error 755: (Info -- global macroWIN32_LEAN_AND_MEAN (line 9, fileD:WORK3SimpleProjectForPClintSimpleProjectForPClintstdafx.h) not referenced)error 900: (Note -- Successful completion, 6 messages produced)Its hard to disagree with. Now you have a wonderful tool in your arms, which will make it possible toyoure your code better and to find both potential and present errors.But if you get the message:PC-lint for C/C++ (NT) Vers. 8.00u, Copyright Gimpel Software 1985-2006--- Module: .pclint.cpp (C++)_#include <stdio.h>D:Sourcespclintstdafx.h(10) : Error 322: Unable to open include file
  37. 37. stdio.hthen it means that you have not set the environment settings and you will have to check theenvironment settings INCLUDE. Let us write in the command lineecho %INCLUDE%As the result you must see:C:Program FilesMicrosoft Visual Studio 8 Microsoft 8VCATLMFCINCLUDE;C:Program Files Program FilesMicrosoft VisualStudio 8VCINCLUDE;C:Program Files Program FilesMicrosoft Visual Studio 8VCPlatformSDK PlatformSDKinclude;C:ProgramFilesMicrosoft Visual Studio 8 Microsoft 8SDKv2.0include;7If the paths to the Visual Studio headline files are absent, then it is necessary to correct the environmentsettings or to write the paths to the files in PC PC-lint configuration files.
  38. 38. Picture 35. Pushing the button F4 in the window Output you can easily navigate among the warnings ofPC-lint.Thats where the installation of PC lint and its integration into Visual Studio 2005 can be considered PC-lintfinished. Your following step must be getting acquainted with the documentation and tuning of theconfiguration files to your specific needs. Good luck in your work!References 1. Wikipedia, "Unit testing", 2. Wikipedia, "Dynamic testing", 3. Wikipedia, "Static testing", ipedia, 4. Wikipedia, "Static code analysis", 5. Wikipedia, "White box t testing", 6. Wikipedia, "Black box testing",