How to make lint find this ...

Hi, I'm using pc-lint 8.0 on a large code-composer project. I'm most interested in using it to find uninitialized pointers. Recently I had a case that my lint check didn't find. Here is a sample program to show the type of problem:

static int * ptr1; // unitialized pointer static int buffer[10];

void initPtr(void); void usePtr(void);

void initPtr(void) { ptr1= buffer; }

void usePtr(void) { int i; for(i=0;i

Reply to
Brian
Loading thread data ...

Hi, I'm using pc-lint 8.0 on a large code-composer project. I'm most interested in using it to find uninitialized pointers. Recently I had a case that my lint check didn't find. Here is a sample program to show the type of problem:

static int * ptr1; // unitialized pointer static int buffer[10];

void initPtr(void); void usePtr(void);

void initPtr(void) { ptr1= buffer; }

void usePtr(void) { int i; for(i=0;i

Reply to
Brian

Use Visual Studio and structure your code;-) VS would flag the following:

void usePtr(int init ) { static int * ptr1; // unitialized pointer static int buffer[10]; int i; for(i=0;i

Reply to
Rick Merrill

Can lint work on projects, or just single files? i.e. Does it know the entire flow of your program, code in an unrelated file may have previously called initPtr() directly or indirectly (through a pointer, or in an ISR). I don't think link can know this (but don't know for sure).

If the uninitialised pointer was at function scope rather than file scope then lint would definately find the problem.

Regards, Richard.

formatting link

Reply to
Richard

This pointer is not uninitialized - it should be initialized to 0 ! (some run time environment does not handle this correctly...)

But when lint fails you could try 'valgrind'

formatting link
When I run the code it reports:

Invalid write of size 4 at 0x........: usePtr (test2.c:16) by 0x........: main (linttest.c:30) Address 0x0 is not stack'd, malloc'd or free'd

[Valgrind is integrated in CVS versions of kdeveloper
formatting link
]

/RogerL

--
Roger Larsson
SkellefteƄ
Sweden
Reply to
Roger Larsson

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.