Sie sind auf Seite 1von 42

C/C++

PCLint
PC-Lint
PC-Lint
PC-Lint


1
2 PC-Lint
3 PC-Lint
3.1
3.2
3.3
3.4
3.5
3.6
3.7 const
3.8 volatile
4 PC-Lint
4.1
4.2 PC-Lint Visual C++,Source Insight,UEdit)
5

PC-Lint

PC-Lint

C/C++
C/C++

C/C++
C/C++
LoGIScope RuleChecker PC-Lint
Logiscope RuleChecker
case
PC-Lint


PC-Lint PC-Lint
Visual C++Source Insight PCLint
PC-Lint
PC-Lint GIMPEL SOFTWARE C/C++
PC-Lint/FlexeLint for C/C++PC-Lint WindowsMSDOS OS/2 FlexeLint
PC-lint
PC-Lint PC-Lint

PC-Lint
1
2char *report( int m, int n, char *p )
3{
4 int result;
5 char *temp;
6 long nm;
7 int i, k, kk;
8 char name[11] = "Joe Jakeson";
9
10 nm = n * m;
11 temp = p == "" ? "null" : p;
12 for( i = 0; i<m; I++ ) {
14 k++;
15 kk = i;
16 }
17
18 if( k== 1 ) result = nm;
19 else if( kk > 0 ) result = 1;
20 else if( kk < 0 ) result = -1;
21
22 if( m == result ) return( temp );
23 else return( name );
24}
C C PC-Lint
8 name
nul 10 long int
11 14

k 15 kk 22 result
23
C++C/C++
BUG C++ Pascal

PC-Lint
PC- Lint

PC-Lint
PC-Lint PC-Lint
1000 C
1000 C++ 1 PCLint
1 PC-Lint

C++

1-199

1001-1199

200-299

300-399

400-699

1400-1699

700-800

1700-1899

900-999

1900-1999

C 1-199
200-299 PC-Lint
300-399 400-999
400699 700-899


900-999

PC-Lint/FelexLint wLevel 3
-w0
-w1 --
-w2
-w3
-w4
PC-Lint/FelexLint wlib(Level) C/C++wLevel 3
-wlib(0)
-wlib(1)
-wlib(2)
-wlib(3)
-wlib(4)
PC-Lint
const volatile
PC-Lint PC-Lint
PC-Lint 300

/*lint option1 option2 ... optional commentary */

//lint option1 option2 ... optional commentary

C++
lint /*//
-esym(534,
printf, scanf, operator new) operator new
operator new PC-Lint

#define DIVZERO(x) /*lint -save -e54 */ ((x) /0) /*lint -restore */


0
PC-Lint

3.1
-strong-index
typedef
strong
-strong( flags[, name] ... )
strong typedef PC-Lint

typedef flags AJXBbl


f 2

2 strong
A


A A
i
r Return
p
a
c

z Zero Zero
0 0L (int)0 Zero
(HANDLE)0 HANDLE
Zero(HANDLE *)0 strong(Ai,BITS)PC-Lint BITS
BITS

i, r, p, a, c, z X

J
e ==!=?:
r >>=<<=
o +-*/%|&^
c
z Zero

Meters

B
1. Boolean
Type Boolean
true false

&&||
2. Bolean if
while

if(a)... a int int


Bolean if(a != 0)

Bolean
Type B b

B b 1bit
Boolean 1bit
Boolean

A J
B b f B b
-strong type
-strong
//lint -strong(Ab,Bool) <>
typedef int Bool;
Bool gt(int a, b)
{
if(a) return a > b; // OK
else return 0; // Warning
}
Bool b return
return
0 Bool c -strong(Acb,Bool)

/*lint -strong( AJXl, STRING ) */


typedef char *STRING;
STRING s;
...
s = malloc(20);
strcpy( s, "abc" );
malloc strcpy malloc s
s strcpy l

Boolean Boolean

//lint -strong( AJXb, Bool )


//lint -strong( AJX, BitField )
typedef int Bool;
typedef unsigned BitField;
struct foo
{
unsigned a:1, b:2;
BitField c:1, d:2, e:3;
} x;
void f()
{
x.a = (Bool) 1; // OK
x.b = (Bool) 0; // strong type violation
x.a = 0; // strong type violation

x.b = 2; // OK
x.c = x.a; // OK
118
x.e = 1; // strong type violation
x.e = x.d; // OK
}
a c Bool d e BitField b
Boolean
Boolean -strong f strong(AJXbf,Bool)
indexindex
-index( flags, ixtype, sitype [, sitype] ... )
strong strong
ixtype Strongly Indexed sitype
ixtype sitype typedef
flags c dc ixtype d
ixtype Dimensions
index
//lint -strong( AzJX, Count, Temperature )
//lint -index( d, Count, Temperature )
// Only Count can index a Temperature
typedef float Temperature;
typedef int Count;
Temperature t[100]; // OK because of d flag
Temperature *pt = t; // pointers are also checked
// ... within a function
Count i;
t[0] = t[1]; // Warnings, no c flag
for( i = 0; i < 100; i++ )
t[i] = 0.0; // OK, i is a Count
119
pt[1] = 2.0; // Warning
i = pt - t; // OK, pt-t is a Count
Temperature Count
d
Temperature t[ (Count) 100 ];

#define MAX_T (Count) 100


Temperature t[MAX_T];

MAX_T for for


pt
[]

i = pt - t;
3.2
3.2.1

LINT 644, 645 (""), 771, 772 ("


"), 530 (""), and 1401 - 1403 (" ... ")

if( a ) b = 6;
else c = b; // 530 message
a = c;
// 645 message
b c PC-Lint b c
c a while
for if
while ( n-- )
{
b = 6;
...
}
c = b; //772 message
b b
c
if
if if
While if
switch ( k )
{
case 1: b = 2; break;
case 2: b = 3;
/* Fall Through */
case 3: a = 4; break;
default: error();
}
c = b; //645 message

b b
b c
switch b PC-Lint
PC-Lint
b case
error() PCLint
switch ( k )
{
case 1: b = 2; break;
case 2:
case 3: b = 3; a = 4; break;
default: error();
/*lint -unreachable */
}
c = b;
-unreachable error()break
free

if( n ) free( p );
...
p->value = 3;
p p goto
goto goto
if ( a ) goto label;
b = 0;
label: c = b;

if( x ) initialize y
...
if( x ) use y
y esym(644,y) y
3.2.2

(1) 415661796
(2) 0 54414795
(3) NULL 413613794

(4) 416662797
(5) 774

int a[10];
int f()
{
int k;
k = 10;
return a[k]; // Warning 415
}
415 '[' PC-Lint
k k
int a[10];
int f( int n )
{
int k;
if ( n ) k = 10;
else k = 0;
return a[k]; // Warning 661
}
661 ()
10 kPC-Lint

int a[10];
int f( int k, int n )
{
if ( k >= 10 ) a[0] = n;
return a[k]; // Warning 661 -- k could be 10
}
661 PC-Lint k k
>=10 K

int a[10];
int f( int k, int n )
{ return a[k+n]; } // no warning

k 796 (
).
int a[10];
int f(int n, int k)
{
int m = 2;

if( k >= 10 ) m++; // Hmm -- So k could be 10, eh?


while( n-- )
{ m++; k = 0; }
return a[k]; // Info 796 - - k could still be 10
}
NULL
int *f( int *p )
{
if ( p ) printf( "\n" ); // So -- p could be NULL
printf( "%d", *p ); // Warning
return p + 2; // Warning
}
NULL
if Pointerparameter-may-be-NULL +fpn
NULL
int a[10]; ... a[10] = 0;
a[-1]PC-Lint

ANSI C([1]3.3.6)

int a[10];
f( a + 10 ); // OK
f( a + 11 ); // error

int a[10], *p, *q;


p = a + 10; // OK
*p = 0; // Warning (Access error)
p[-1] = 0; // No Warning
q = p + 1; // Warning (creation error)
q[0] = 0; // Warning (access error)

if ( n > 0 ) n = 0;
else if ( n <= 0 ) n = -1; // Info 774
774

3.2.3 assert
PC-Lint

assert


char buf[4];
char *p;
strcpy( buf, "a" );
p = buf + strlen( buf ); // p is 'possibly' (buf+3)
p++; // p is 'possibly' (buf+4)
*p = 'a'; // Warning 661 - possible out-of-bounds reference
PC-Lint

*p = 'a'; //lint !e661


assert
#include <assert.h>
...
char buf[4];
char *p;
strcpy( buf, "a" );
p = buf + strlen( buf );
assert( p < buf + 3 ); // p is 'possibly' (buf+2)
p++; // p is 'possibly' (buf+3)
*p = 'a'; // no problem
assert NDEBUG Lint

assert() assert.h
assert

#define assert(p) ((p) ? (void)0 : __A(...))


__A()
-function( exit, __A )
exit __A
assert
#define assert(k) _Assert(k,...)
PC-lint _Assert assert function( __assert, _Assert )-function( __assert(1), _Assert(1) )
__assert()

assert.h PC-lint -i

3.2.4
PC-Lint


t1.cpp:
1 int f(int);
2 int g()
3 { return f(0); }
4 int f( int n )
5 { return 10 / n; }
f() 0
10/n 0 lin -u t1.cpp
--- Module: t1.cpp
During Specific Walk:
File t1.cpp line 3: f(0)
t1.cpp 5 Warning 414: Possible division by 0 [Reference:File t1.cpp:
line 3]
During Specific Walk

t2.cpp:
1 int f( int n )
2 { return 10 / n; }
3 int g()
4 { return f(0); }
0 f(0) f()
multi-pass
lin -u -passes(2) t2.cpp
--- Module: t2.cpp
/// Start of Pass 2 ///
--- Module: t2.cpp
During Specific Walk:
File t2.cpp line 4: f(0)
t2.cpp 2 Warning 414: Possible division by 0 [Reference:File t2.cpp:
line 4]
-passes(2)
-passes(2)-passes=2 -passes[2]
pass 2


t3.cpp:
1 int f( int n )
2 { return n - 1; }
3 int g( int n )

4 { return n / f(1); }
lin -u -passes(2) t3.cpp
--- Module: t3.cpp
/// Start of Pass 2 ///
--- Module: t3.cpp
{ return n / f(1); }
t3.cpp 4 Warning 414: Possible division by 0 [Reference:File t3.cpp:
lines 2, 4]
f() 1
f() 0
g() 0 During
Specific Walk g()
g()
pass

t4.cpp:
1 int f(int);
2 int g( int n )
3 { return f(2); }
4 int f( int n )
5 { return n / f(n - 1); }
f(n-1) f(2) f(1)
f(0) 0
lin -u -passes(3) t4.cpp

--- Module: t4.cpp


{ return f(2); }
t4.cpp 3 Info 715: Symbol 'n' (line 2) not referenced
/// Start of Pass 2 ///
--- Module: t4.cpp
/// Start of Pass 3 ///
--- Module: t4.cpp
During Specific Walk:
File t4.cpp line 3: f(2)
File t4.cpp line 5: f(1)
t4.cpp 5 Warning 414: Possible division by 0 [Reference:File t4.cpp:
lines 3, 5]
0
-specific_wlimit(n)
f(2)f(2)
3.3

564 C/C++

n++ + n
+

a[i] = i++;
f( i++, n + i );

&&||? :
(,)
if( (n = f()) && n > 10 ) ...

if( (n = f()) & n > 10 ) ...

3.4
typedef
PC-Lint
PC-Lint 749-769 1749-1769

(1) #include PC-Lint


766
(2)
PC-Lint 759
(3) PC-Lint 765
static
PC-Lint

lint -w1 +e749 +e?75? +e?76? ...


......
3.5
PC-Lint printf scanf()
printf( "%+c", ... )
566

557 567 ANSI C


558, 559, 560 561 %d

int unsigned int double long long


int scanf
626 627 -printf -scanf
printf scanf -printf_code
-scanf_code %
3.6
PC-Lint

if( ... )
if( ... )
statement
else statement
else if
if PC-Lint
725(no positive indentation)525(negatively indented
from)539Did not expect positive indentation from Location
tab
8 -t# -t4 tab 4

3.7 const
const PC-Lint const

char *strcpy( char *, const char * );


const char c = 'a';
const char *p = &c;
void main()
{
char buf[100];
c = 'b';
*p = 'c';
strcpy( p, buf );
...
c *P
Error(11) P strcpy
605Increase in pointer capability buf
strcpy 603Symbol 'Symbol' (Location) not
initialized buf
strcpy
3.8 volatile

volatile PC-Lint
volatile 564

volatile char *p;


volatile char f();
n = (f() << 8) | f(); /* Warning 564 */
n = (*p << 8) | *p; /* Warning 564 */

PC-Lint
4.1
PC-lint
PC-lint
lint-nt u std.lnt test1.c test2.c test3.c
MAKEFILE
Source Insight/SLICKEDIT/MS VC6.0/KEIL C..PC-Lint
Scott Meyes Effective C++/More Effective C++

PC-lint PC-lint 8.0


c:\pclint8 PC-lint
config.exe config.exe
C:\pclint8\config.exePC- lint
std.lnt

Microsoft Visual C+
+ 6
C:\pclint8\config.exe
4.1

4.1
pc-lint.exe 4.2

4.2 pc-lint.exe

STD.LNT

4.3 STD.LNT
Create a new STD.LNT
STD.LNT
STD_x.LNT x az26
aSTD_x.LNT STD.LNT
4.3 PC-Lint

4.4

Microsoft Visual C++ 6.x (co-msc60.lnt)


Generic Compilers co-xxx.lnt
C:\PCLint8
***.LNT

4.5

STD.LNT STD_x.LNT
32 Windows32-bit Flat Model

4.6
PC-Lint

STD.LNT STD_x.LNT
ATLMFCSTL

4.7
C/C++

AUxxx.LNT

4.8
-i

-i STD.LNT STD_x.LNT
-i
-iE:\Program Files\Microsoft Visual
C++\VC98\Indlue-i

4.9
;
ctrl+Enter Brows

4.10 std_x.lnt
Create a new STD.LNT
std_x.lntstd.lnt std_a.lnt
std.lnt

4.11

4.12 std.lnt
std_x.lnt std.lnt
std_x.lnt std.lnt

4.13 OPTIONS.LNT

OPTIONS.LNT

OPTIONS.LNT -e

OPTIONS.LNT
No

4.14
PC-Lint
VCBCSource Insight
Microsift Visual C++ 6.0 env-v6.lnt

4.15 LIN.BAT
LIN.BAT PC-Lint

LIN.BAT PATH
LSET.BAT PC-LINT
LSET.BAT AUTOEXEC.BAT
PC-Lint copy
LIN.BAT to one of my PATH directory PATH

4.16 PATH
C:\PCLint8 PATH

4.17
PC-Lint PC-Lint
*.lnt
std.lntstd_x.lnt option.lnt co-xxx.lntlibxxx.lntenv-xxx.lnt
PCLint lnt lnt

PC-lint
*.lnt

4.2 PC-Lint
PC-Lint

4.2.1
PC-lint
PC-lint PC-lint

Lint-nt option file1 [file1 file3 ]


Lint-nt PC-lint Windows NT/2000/XP
Lint-nt.exe PC-lint option PC-lint
PC-lint 300

file

*.lnt

4.2.2 PC-Lint Visual C++IDE


PC-Lint 8.0 VC++6 VC++7.0
VC VC6 *.dspVC7 *.vcproj
.Lnt
.Lnt
PC-Lint VC VC
ToolsCustomize...
Customize Tools
VC .Lnt
.Lnt

lint-nt.exe +linebuf $(TargetName).dsp>$(TargetName).lnt


+linebuf 600 bytes
$(TargetName) VC
Project Use Output Window
PC-Lint Output 4.18

4.18 .Lnt

lint-nt.exe -i"C:\PCLint8" -u std_g.lnt env-vc6.lnt "$(FileName)$


(FileExt)"
-i"C:\PCLint8" PC-Lint *.lnt
std_g.lnt VC $(FileName)$
(FileExt) VC "$(FileName)$(FileExt)"
.Lnt VC
Output Use Output Window
4.19

4.19

lint-nt.exe +ffn -i"C:\PCLint8" std_g.lnt env-vc6.lnt $


(TargetName).lnt>$(TargetName).chk
.chk
+ffn Full File Names

VC PC-Lint
Win32 Console ApplicationHello
World

stdafx.h
std_g.lnt std_g.lnt,

-iC:\unzipped\test
C:\unzipped\test stdafx.h

PC-Lint

test.cpp ToolsPC_LINT 8.0 Check Current File


Output 4.20

4.20
4.2.3 PC-Lint source insight
PC-Lint source insight
OptionsCustom CommandsAdd
4.21 Custom Commands
Name PC-lint Check Current File

Run C:\PcLint\lint-nt -u -iC:\PcLint\Lint std_f env-si %f


C:\PcLint PC-LINT std_f Source Insight
std_f.lnt
Output Iconic WindowCapture Output
Control Save Files First
Source Links in Output Parse Links in OutputFilethen
Line
Pattern ^\([^ ]*\) \([0-9]+\)

4.21 Source Insight


Run PC-Lint
Menu... Source
Insight
4.2.4 PC-Lint UltraEdit
UltraEdit PC-Lint Source Insight
UltraEdit
4.22
PC-lint Check Current File
C:\PCLint\lint-nt u -iC:\PCLint std env-si
%f C:\PCLint PC-Lint std.lnt
UltraEdit Source Insightde env-si

E:\code

UltraEdit

4.22 UltraEdit
UltraEdit PC-lint Check Current File
PC-lint


PC-lint
PC-Lint

PC-lint
PC-lint

[1] Gimpel Software. Reference Manual for PC-lint/FlexeLint.


July,2001
[2] PC-Lint
PC-Lint

Msg.txt
options.lnt

env-xx.lnt PC-lint xx si
Source Insight xx vc6 Visual C++
6.0
co-xxx.lnt
std.lnt
lib-xxx.lnt C/C++MFC OWL

au-xxx.LNT C++

-e#
-e(#)

all);
!e#

printf(its all);
-esym(#, Symbol)
printf)*/

/*lint -e725 */
/*lint e(534) */
printf(its
/*lint !e534*/
/*lint esym(534,
printf(its

all);
-elib(#)

r01.h
-efunc(#, <func>)
mchRelAll)*/

/*lint elib(129) */
#include
/*lint efunc(534,
unsigned int

mchRelAll(mchHoData
*pHoData)
{
printf(its
all);
}
PC-Lint

40
506 Boolean
char c=3;
if(c<300){}
525
527 if(a > B)
return TRUE;
else
return FALSE;
return FALSE;
529

530
534
539
545 &
char arr[100], *p;
p=&arr;
603
void print_str(const char *p);

char *sz;
print_str(sz);
605
void write_str(char *lpsz);

write_str(string);
613
616 switch break;
650 if( ch == 0xFF ) ...

713

715
725 Indentation
734 int a, b, c;

c=a*b;
737 /
/
744 switch default
752
762
774 Boolean / char c;
if(c < 300)
@ 2006 07 24 23:33:00|(9

)|

: C/C++ SMC | :
PC-Lint( )

#abenking 2006-08-23 00:23:00 IP: 58.60.139.*


PCLINT8
#abenking 2006-08-26 00:49:00 IP: 58.61.138.*
PCLINT
#orbit 2006-08-26 15:31:00 IP: 222.71.109.*

#abenking 2006-08-31 21:38:00 IP: 59.40.89.*


..
#mukey 2007-08-07 11:14:38 IP: 61.148.100.*
:
[2] PC-Lint
, .

/************************/
#include <stdio.h>
void p(int i)
{
printf( "%d\n", i);
}
int main(int argc, char** argv)
{
int a = 1;
p(a);
return 0;
}
/*******************************/

dos :
C:\lint>lint-nt -u std.lnt c:\a.c
PC-lint for C/C++ (NT) Ver. 8.00e, Copyright Gimpel Software
1985-2001
options.lnt(8) : Error 90: Option '-e(970)' is only appropriate
within a lint
comment

--- Module: c:\a.c


_
#include <stdio.h>
c:\a.c(1) : Info 829: A +headerwarn option was previously
issued for header
'stdio.h' [MISRA Rule 124]
_
void p(int i)
c:\a.c(2) : Note 970: Use of modifier or type 'int' outside of a
typedef [MISRA
Rule 13]
_
{
c:\a.c(3) : Note 957: Function 'p' defined without a prototype
in scope [MISRA
Rule 71]
_
int main(int argc, char** argv)
c:\a.c(6) : Note 970: Use of modifier or type 'int' outside of a
typedef [MISRA
Rule 13]
c:\a.c(6) : Note 970: Use of modifier or type 'int' outside of a
typedef [MISRA
Rule 13]
c:\a.c(6) : Note 970: Use of modifier or type 'char' outside of a
typedef
[MISRA Rule 13]
c:\a.c(6) : Note 971: Use of 'char' without 'signed' or
'unsigned' [MISRA Rule
14]
_
int a =
#mukey 2007-08-07 11:16:07 IP: 61.148.100.*
:
c:\a.c(6) : Note 971: Use of 'char' without 'signed' or
'unsigned' [MISRA Rule
14]
_
int a = 1;
c:\a.c(8) : Note 970: Use of modifier or type 'int' outside of a
typedef [MISRA
Rule 13]

_
}
c:\a.c(11) : Info 715: Symbol 'argv' (line 6) not referenced
c:\a.c(6) : Info 830: Location cited in prior message
_
}
c:\a.c(11) : Info 818: Pointer parameter 'argv' (line 6) could be
declared as
pointing to const
c:\a.c(6) : Info 830: Location cited in prior message
_
}
c:\a.c(11) : Info 715: Symbol 'argc' (line 6) not referenced
c:\a.c(6) : Info 830: Location cited in prior message
C:\lint>
warnning, info, 829,970 ,
#orbit 2007-08-13 19:15:26 IP: 222.71.114.*
option option
typedef
typedef unsigned int UINT;
UINT unsigned int
#sdhzzzzcd 2007-08-21 18:02:45 IP: 124.207.98.*
PC LINT8.0 Check Current File
VS2005
PC-lint for C/C++ (NT) Vers. 8.00w, Copyright Gimpel Software
1985-2007
--- Global Wrap-up
error 900: (Note -- Successful completion, 0 messages
produced)
#sdhzzzzcd 2007-08-21 18:05:11 IP: 124.207.98.*
PC LINT8.0 Check Project
PC-lint for C/C++ (NT) Vers. 8.00w, Copyright Gimpel Software
1985-2007
error 305: (Error -- Unable to open module 'Test.lnt>Test.chk')

Das könnte Ihnen auch gefallen