You are on page 1of 8

Cppcheck

Cppcheck - ++.
: , ,
, .
: http://cppcheck.sourceforge.net/
Cppcheck , , GNU
General Public License. Daniel Marjamki (
StackOverflow). github.

Cppcheck
Cppcheck 1.60.1 : C89,
C99, C11, C++03, C++11. , ,
:

Code::Blocks - integrated
CodeLite - integrated
Eclipse - Cppcheclipse
gedit - gedit plugin
Hudson - Cppcheck Plugin
Jenkins - Cppcheck Plugin
Tortoise SVN - Adding a pre-commit hook script
Mercurial (Linux) - Adding a pre-commit hook script
Visual Studio / Eclipse - Visual Lint by RiverBlade ( )

Cppcheck
Cppcheck .

. , Cppcheck Windows, GUI ,
.

1. Cppcheck Windows. . .
"Check directory" .
.

2. . .
, , , Cppcheck .
Cppcheck, . ,
, Cppcheck
. , ,

- ! ,
. .
.
: Errors, Warnings, Style Warnings, Portability Warnings, Performance Warnings,
Information Messages. / .
N3 Style Warnings.
"Style Warnings" , (. 1). "cpuid_x86.c"
. , 214
(. 2). (. 3).

3. .
.

Cppcheck .
:

Standard Template Library;


(Memory leaks);
(Resource leaks);
(Bounds checking for array overruns);
;
;
/ (Check input/output operations);
.

: Checks.


, Cppcheck.

N1. MPlayer.
.
"(!sh->wf || sh->wf->cbSize < 80)", .
....
context_t *ctx = calloc(1, sizeof(context_t));
const SpeexMode *spx_mode;
const SpeexStereoState st_st = SPEEX_STEREO_STATE_INIT;
if (!sh->wf || sh->wf->cbSize < 80) {
mp_msg(MSGT_DECAUDIO, MSGL_FATAL, "Missing extradata!\n");
return 0;
}
....
:
libmpcodecs/ad_speex.c:44: Memory leak: ctx

N2. Doom 3.
"sizeof(ctx)" "sizeof(*ctx)". -
'ctx' .
void MD5_Final( MD5_CTX *ctx, unsigned char digest[16] ) {
....
memset( ctx, 0, sizeof( ctx ) );
:
..\Doom3\id-Software-DOOM-3-a9c49da\neo\idlib\hashing\MD5.cpp(252):
Using size of pointer ctx instead of size of its data.

N3. Doom 3.
, , ,
. delete [] sortIndex.
void idImageManager::PrintMemInfo( MemInfo_t *mi ) {
int *sortIndex;
....

sortIndex = new int[images.Num()];


....
delete sortIndex;
:
..\Doom3\id-Software-DOOM-3-a9c49da\neo\renderer\Image_init.cpp(2214)
Mismatching allocation and deallocation: sortIndex

N4. Quake 3: Arena.


. , .
void RB_CalcColorFromOneMinusEntity( unsigned char *dstColors )
{
...
unsigned char invModulate[3];
...
invModulate[0] = 255 - backEnd.currentEntity->e.shaderRGBA[0];
invModulate[1] = 255 - backEnd.currentEntity->e.shaderRGBA[1];
invModulate[2] = 255 - backEnd.currentEntity->e.shaderRGBA[2];
invModulate[3] = 255 - backEnd.currentEntity->e.shaderRGBA[3];
// this trashes alpha, but the AGEN block fixes it
:
..\Quake3\id-Software-Quake-III-Arena-dbe4ddb\code\renderer\tr_shade_calc.c 628
Array 'invModulate[3]' index 3 out of bounds

N5. Quake 3: Arena.


printf() , . ,
.
static void do_uid(int x) {
printf("<a href='#%d'>%d</a>", x, x, x);
}
:

..\Quake3\id-Software-Quake-III-Arena-dbe4ddb\lcc\src\2html.c 131
printf format string has 2 parameters but 3 are given

1.
2.
3.
4.
5.
6.
7.
8.
9.

Website: http://cppcheck.sourceforge.net/
Wikipedia: Cppcheck.
Cppcheck forum.
Cppcheck manual: HTML, PDF.
Cppcheck git repository.
, Cppcheck.
Cppcheck. Cppcheck: free, easy, and great.
. Cppcheck PVS-Studio.
Aleksey Vitebskiy. Poor Man's Visual Studio Cppcheck Integration.