A Report Generator for PC-Lint
by Jon Zyzyck


Listing One
#include <stdio.h>
// This is a short file to show some examples of PC-Lint error/warning
// detection and reporting of common errors
/*lint +e716*/
#define MAX_BUF ( 1024 )
void main()
{
char buf[MAX_BUF];
int i;
for (i = 0; i < MAX_BUF; i++)
    {
buf[i+1] = 0; // Warning 661: Possible access of out-of-bounds pointer
    }
char sbuf[1024];
float fVal;
float fMax = 100.0;
int nCount = 0;
fVal = fMax/nCount; // Warning 414: Possible division by 0
//                                 sprintf(sbuf, "the answer is: %d", fVal);
// Warning 559: Size of argument no. 3 inconsistent with
//                    format sprintf(sbuf, "the answer is: %g for %d", fVal);
// Warning 558: Too few arguments for format (1 missing)
//                                      int nRet; int nTest = nRet * 10;
// Warning 530:Symbol 'nRet' (line 28) not initialized int nFoo;switch (nTest)
    {
case 1:
nFoo = 1; break;
case 2:
nFoo = 21;
case 3:
// Info 825: control flows into case/default
//                            without -fallthru comment nFoo = 321; break;
    }
int nFooVal = nFoo;
// Warning 644: Variable 'nFoo' (line 31) may not have
//                             been initialized int nTest2 = 0; for(;;)
    {
nTest2++;
if (nTest2 > nFoo)
goto done; // Info 801: Use of goto is deprecated
    }
done:
unsigned int nTest3 = 1; while (1) // Info 716: while(1) ...
    {
nTest3 = nTest3 << 1;
    }
//Warning 527: Unreachable
int nTest4 = 0;
if (nTest4 == 0)
// Info 774: Boolean within 'if' always evaluates to True
     {
     }
float *fTest;
int *Int;
pInt = (int *) &fTest;
// Info 740: Unusual pointer cast (incompatible indirect types)
//                                     int *pInt; unsigned char nByte;
*pInt = (int *) &nByte;
// Info 826: Suspicious pointer-to-pointer conversion (area too small)
}


Listing Two
C:\Projects\jzLintReport>echo off
Current date is Fri 10-25-2002
Enter new date (mm-dd-yy):
Current time is  3:12:30.06p
Enter new time:

--- Module:   C:\Projects\jzLintReport\example.cpp
                    _
        buf[i+1] = 0; // Warning 661: Possible access of out-of-bounds pointer
C:\Projects\jzLintReport\example.cpp(18) :  Warning 661: Possible access of
out-of-bounds pointer (1 beyond end of data) by operator '['
C:\Projects\jzLintReport\example.cpp(16) :  Info 831: Reference cited in prior
message
C:\Projects\jzLintReport\example.cpp(18) :  Info 831: Reference cited in prior
message
                      _
    fVal = fMax/nCount; // Warning 414: Possible division by 0
C:\Projects\jzLintReport\example.cpp(25) :  Warning 414: Possible division by 0
C:\Projects\jzLintReport\example.cpp(24) :  Info 831: Reference cited in prior
message
                                            _
    sprintf(sbuf, "the answer is: %d", fVal); // Warning 559: Size of argument
no. 3 inconsistent with format
C:\Projects\jzLintReport\example.cpp(26) :  Warning 559: Size of argument no. 3
inconsistent with format
                                                   _
    sprintf(sbuf, "the answer is: %g for %d", fVal); // Warning 558: Too few
arguments for format (1 missing)
C:\Projects\jzLintReport\example.cpp(27) :  Warning 558: Too few arguments for
format (1 missing)
                         _
    int nTest = nRet * 10; // Warning 530: Symbol 'nRet' (line 28) not
initialized
C:\Projects\jzLintReport\example.cpp(30) :  Warning 530: Symbol 'nRet' (line 29)
not initialized
    _
    case 3:            // Info 825: control flows into case/default without
-fallthrough comment
C:\Projects\jzLintReport\example.cpp(40) :  Info 825: control flows into
case/default without -fallthrough comment
                      _
    int nFooVal = nFoo; // Warning 644: Variable 'nFoo' (line 31) may not have
been initialized
C:\Projects\jzLintReport\example.cpp(44) :  Warning 644: Variable 'nFoo' (line
32) may not have been initialized
            _
            goto done; // Info 801: Use of goto is deprecated
C:\Projects\jzLintReport\example.cpp(52) :  Info 801: Use of goto is deprecated
            _
    while (1) // Info 716: while(1) ...
C:\Projects\jzLintReport\example.cpp(57) :  Info 716: while(1) ...
    _
    int nTest4 = 0;
C:\Projects\jzLintReport\example.cpp(64) :  Warning 527: Unreachable
                   _
    if (nTest4 == 0) // Info 774: Boolean within 'if' always evaluates to True
C:\Projects\jzLintReport\example.cpp(65) :  Info 774: Boolean within 'if' always
evaluates to True
C:\Projects\jzLintReport\example.cpp(64) :  Info 831: Reference cited in prior
message
C:\Projects\jzLintReport\example.cpp(65) :  Info 831: Reference cited in prior
message
    _
    pInt = (int *) &fTest; // Info 740: Unusual pointer cast (incompatible
indirect types)
C:\Projects\jzLintReport\example.cpp(71) :  Error 40: Undeclared identifier
'pInt'
C:\Projects\jzLintReport\example.cpp(71) :  Info 740: Unusual pointer cast
(incompatible indirect types)
C:\Projects\jzLintReport\example.cpp(71) :  Error 63: Expected an lvalue
                          _
    *pInt = (int *) &nByte; // Info 826: Suspicious pointer-to-pointer
conversion (area too small)
C:\Projects\jzLintReport\example.cpp(75) :  Error 64: Type mismatch (assignment)
(int = pointer)
C:\Projects\jzLintReport\example.cpp(75) :  Info 826: Suspicious
pointer-to-pointer conversion (area too small)
C:\Projects\jzLintReport\example.cpp(75) :  Warning 530: Symbol 'pInt' (line 73)
not initialized


********************************************************

*            Lint Error/Warning messages follow         *

*********************************************************


********** Category: OTHER - Messages that haven't been defined in a category
C:\Projects\jzLintReport\example.cpp(71) :  Error 40: Undeclared identifier
'pInt'
C:\Projects\jzLintReport\example.cpp(71) :  Error 63: Expected an lvalue
C:\Projects\jzLintReport\example.cpp(75) :  Error 64: Type mismatch (assignment)
(int = pointer)
C:\Projects\jzLintReport\example.cpp(25) :  Warning 414: Possible division by 0
C:\Projects\jzLintReport\example.cpp(64) :  Warning 527: Unreachable
C:\Projects\jzLintReport\example.cpp(30) :  Warning 530: Symbol 'nRet' (line 29)
not initialized
C:\Projects\jzLintReport\example.cpp(75) :  Warning 530: Symbol 'pInt' (line 73)
not initialized
C:\Projects\jzLintReport\example.cpp(44) :  Warning 644: Variable 'nFoo' (line
32) may not have been initialized
C:\Projects\jzLintReport\example.cpp(18) :  Warning 661: Possible access of
out-of-bounds pointer (1 beyond end of data) by operator '['
C:\Projects\jzLintReport\example.cpp(57) :  Info 716: while(1) ...
C:\Projects\jzLintReport\example.cpp(65) :  Info 774: Boolean within 'if' always
evaluates to True
C:\Projects\jzLintReport\example.cpp(52) :  Info 801: Use of goto is deprecated
C:\Projects\jzLintReport\example.cpp(40) :  Info 825: control flows into
case/default without -fallthrough comment
********** Category: Critical Errors
C:\Projects\jzLintReport\example.cpp(27) :  Warning 558: Too few arguments for
format (1 missing)
C:\Projects\jzLintReport\example.cpp(26) :  Warning 559: Size of argument no. 3
inconsistent with format
C:\Projects\jzLintReport\example.cpp(71) :  Info 740: Unusual pointer cast
(incompatible indirect types)
C:\Projects\jzLintReport\example.cpp(75) :  Info 826: Suspicious
pointer-to-pointer conversion (area too small)
********** Category: Less Critical Errors
 No messages have been defined for this category
********** Category: Noise Messages
 No messages have been defined for this category

Total Files Processed: 1
Total Files With Messages: 1
Total Messages Processed: 17
Current date is Fri 10-25-2002
Enter new date (mm-dd-yy):
Current time is  3:12:31.81p
Enter new time:

C:\Projects\jzLintReport>rem ************ Done **************

C:\Projects\jzLintReport>
C:\Projects\jzLintReport>
C:\Projects\jzLintReport>
C:\Projects\jzLintReport>

Tool returned code: 0
