Does pc-lint catch this type of problem?

Discussion in 'C Programming' started by Brian, Apr 12, 2004.

  1. Brian

    Brian Guest

    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,
    Brian, Apr 12, 2004
    #1
    1. Advertising

  2. Brian

    Tom St Denis Guest

    Brian wrote:

    > 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
    Tom St Denis, Apr 12, 2004
    #2
    1. Advertising

  3. Brian

    Brian Guest

    Tom St Denis <> wrote in message news:<kaAec.1793$>...
    > Brian wrote:
    >
    > > 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.
    Brian, Apr 12, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Greg Roberts
    Replies:
    33
    Views:
    6,646
    Mark McIntyre
    Feb 5, 2004
  2. Greg Roberts

    Any C/C++ LINT type checking recomendations

    Greg Roberts, Feb 1, 2004, in forum: C Programming
    Replies:
    31
    Views:
    1,703
    Mark McIntyre
    Feb 5, 2004
  3. Rahul
    Replies:
    2
    Views:
    378
    Peter Shaggy Haywood
    Feb 27, 2004
  4. John
    Replies:
    1
    Views:
    347
    Victor Bazarov
    Aug 22, 2007
  5. David Sudolcan
    Replies:
    7
    Views:
    2,057
    Eric Sosman
    Apr 4, 2011
Loading...

Share This Page