Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using PC-Lint on project with third party libraries

I have a project which includes a large third party library and am required to ensure that the project is lint-free. However, the library has several thousand errors.

Modifying the library to remove these is not an option - how would this typically be handled?

Currently, the code is built using Keil uVision and this is where PC-Lint is called from so if this could still be the case that would be best.

Is there a way to specify that these are library files and so should not be analysed?

Thanks.

like image 474
Mark Avatar asked May 26 '13 21:05

Mark


1 Answers

Here is the info from the Gimpel website, I believe that it covers the options you are looking for (bold added for emphasis):

Lint uses the label of "library" header to designate those headers over which a programmer has no control (such as compiler headers). By default all #includes from a foreign directory, or enclosed within < > , are considered "library." This can be modified through the use of the +libclass option, and further fine-tuned with the +/-libdir and +/-libh options. You can then use the -wlib , -elib and -elibsym options to control just those messages being emitted from library headers. Compiler options files distributed with PC-lint usually contain a -wlib(1) option which limits lint output from library headers to errors only (suppressing warning and informational messages).

You can find more information at the Gimpel site here.

Also, if I remember correctly, -wlib(0) suppresses all library errors and warnings... as opposed to the -wlib(1) mentioned above. I will have to double check when I get back to work. I don't have a copy of the manual with me.

---EDIT---

If it is an option, I would place all of the files associated with the library in a different directory. In Keil, you can go to "Tools->Set-up PC-Lint". Then add your new directory to the list of "PC-Lint Include Folders". Your -wlib(0) option should then treat those headers as 'foreign' and not return errors. Of course, you would have to modify the project settings to compile the library files as well.

---EDIT2 Added Example---

Okay, so here is a little test I tried to ensure that my suggestion would work. I created a project in a directory I named "ex_lib" and named the project lib_test. In "Source Group 1" I created and added the file "main.c":

main.c

#include <lib_test.h>

int main (void)
{
    uint16_t x = 5;
    uint16_t y = 10;
    uint16_t total1 = 0;
    uint16_t total2 = 0;
    uint16_t total3 = 0;
    uint16_t total4 = 0;


    total1 = add(x,y);
    total2 = sub(x,y);
    total3 = mult(x,y);
    total4 = div(x,y);

    return 0;
}

I then created a sub-directory named "library" and created a second project named library in that directory. The library project consisted of the following files "lib_test.h" and "lib_test.c".

lib_test.h

#ifndef LIB_TEST__
#define LIB_TEST__

#include <stdint.h>

extern uint16_t add(uint16_t x, uint16_t y);
extern uint16_t sub(uint16_t x, uint16_t y);
extern uint16_t mult(uint16_t x, uint16_t y);
extern uint16_t div(uint16_t x, uint16_t y);

#endif /* LIB_TEST__ */

lib_test.c

#include "lib_test.h"

uint16_t add(uint16_t x, uint16_t y)
{
    return (x + y);
}

uint16_t sub(uint16_t x, uint16_t y)
{
    return (x - y);
}

uint16_t mult(uint16_t x, uint16_t y)
{
    return (x * y);
}

uint16_t div(uint16_t x, uint16_t y)
{
    return (x / y);
}

In the library project, under "Options for Target 'Target 1'", I selected "Create Library". I then compiled the library project.

After successfully compiling, I went back to the lib_test project and right-clicked on "Target1" and selected "Add Group". I created a group called "Library" and added the previously compiled "library.lib" from the "library" directory to the "Library" group.

Finally, under the options for Target 1 (in the lib_test project), I went to the "C/C++" tab and added "library" to the "Include Paths". I was then able to successfully compile (with some warnings about variables being set but never used) the lib_test project. Under "Tools->Set-up PC-Lint" I added the following:

PC-Lint Include Folders: C:\Keil_ARM\RV31\INC\ and library\

Lint Executable: C:\Lint\LINT-NT.EXE

Configuration File: C:\Lint\lnt\CO-RV.LNT

I modified the CO-RV.LNT file to verify my Lint results by modifying -wlib(). When I ran Lint with -wlib(0) I received no warnings or errors about my library files. I then changed -wlib(2) and I received numerous warnings about stdint.h.

This is definitely an oversimplification but it should give you a good starting point. Also, I received Lint warnings about my variables not being accessed in "main.c" but I expected that.

like image 51
embedded_guy Avatar answered Oct 15 '22 05:10

embedded_guy