Does pc-lint catch this type of problem?

B

Brian

I am new to lint and have been experimenting with splint. An
initialization problem I was caught on recently was not found by
splint. Would pc-lint catch this problem:

/* test program for splint */
/* body of func1 commented out to recreate lack of initialization */
static int x[3];
void func1( void);
int func2(void);
void func3(int *);

void func1( void)
{
/* when commented out,
x[0]= 0;
x[1]= 1;
x[2]= 2;
x[] is not initialized */
}

int func2(void)
{
int y;
func3(&x[0]);
y= x[0] + x[1] + x[2];
return y;
}

void func3(int * u)
{
/* some filter code */
u[2]= u[1];
u[1]= u[0];
}

Splint 3.1.1 --- 12 April 2003
Finished checking --- no warnings

Thanks,
 
T

Tom St Denis

Brian said:
I am new to lint and have been experimenting with splint. An
initialization problem I was caught on recently was not found by
splint. Would pc-lint catch this problem:

/* test program for splint */
/* body of func1 commented out to recreate lack of initialization */
static int x[3];

x[] == {0, 0, 0}

It is initialized.

void func1( void);
int func2(void);
void func3(int *);

void func1( void)
{
/* when commented out,
x[0]= 0;
x[1]= 1;
x[2]= 2;
x[] is not initialized */
}

int func2(void)
{
int y;
func3(&x[0]);

You could write that as x instead of &x[0].
y= x[0] + x[1] + x[2];

This is valid because x[] == {0, 0, 0}
return y;
}

void func3(int * u)
{
/* some filter code */
u[2]= u[1];
u[1]= u[0];
}

Splint 3.1.1 --- 12 April 2003
Finished checking --- no warnings

The code is valid. Also from the point of view of just looking at the
functiosn blindly func3() is always valid (it doesn't use the globals).

Tom
 
B

Brian

Tom St Denis said:
Brian said:
I am new to lint and have been experimenting with splint. An
initialization problem I was caught on recently was not found by
splint. Would pc-lint catch this problem:

/* test program for splint */
/* body of func1 commented out to recreate lack of initialization */
static int x[3];

x[] == {0, 0, 0}

It is initialized.

void func1( void);
int func2(void);
void func3(int *);

void func1( void)
{
/* when commented out,
x[0]= 0;
x[1]= 1;
x[2]= 2;
x[] is not initialized */
}

int func2(void)
{
int y;
func3(&x[0]);

You could write that as x instead of &x[0].
y= x[0] + x[1] + x[2];

This is valid because x[] == {0, 0, 0}
return y;
}

void func3(int * u)
{
/* some filter code */
u[2]= u[1];
u[1]= u[0];
}

Splint 3.1.1 --- 12 April 2003
Finished checking --- no warnings

The code is valid. Also from the point of view of just looking at the
functiosn blindly func3() is always valid (it doesn't use the globals).

Tom

Ah! your right. I wonder why my embedded DSP code had garbage in x
until I explicitly initialized it. Maybe the boot loader isn't
initializing static data ?
In any case thanks for your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top