Вы находитесь на странице: 1из 7

PVS-Studio: Doom 3

:
: 25.11.2011
id Software PVS-Studio. ,
Doom 3, . -
, - . , .

Doom3 , , .
. , .
, , ,
PVS-Studio. ,
. , .
Doom 3 GitHub FTP
GPL v3. PVS-Studio 4.39.
. , PVS-Studio.
, .

1. .
#define BIT( num ) ( 1 << ( num ) )
const int BUTTON_ATTACK = BIT(0);
void idTarget_WaitForButton::Think( void ) {
...

if ( player &&
( !player->oldButtons & BUTTON_ATTACK ) &&
( player->usercmd.buttons & BUTTON_ATTACK ) ) {
...
}
PVS-Studio: V564 The '&' operator is applied to bool type value. You've
probably forgotten to include parentheses or intended to use the '&&' operator. Game target.cpp 257
"!player->oldButtons & BUTTON_ATTACK". ,
0. '!' , '&'. ,
:
(!player->oldButtons) & 1
, , . :
if ( player &&
( ! ( player->oldButtons & BUTTON_ATTACK ) ) &&
( player->usercmd.buttons & BUTTON_ATTACK ) ) {

2. .
void idSurface_Polytope::FromPlanes(...)
{
...
for ( j = 0; j < w.GetNumPoints(); j++ ) {
for ( k = 0; k < verts.Num(); j++ ) {
if ( verts[k].xyz.Compare(w[j].ToVec3(),
POLYTOPE_VERTEX_EPSILON ) ) {
break;
}
}
...
}
...
}

PVS-Studio: V533 It is likely that a wrong variable is being incremented


inside the 'for' operator. Consider reviewing 'j'. idLib surface_polytope.cpp 65
'j', 'k'. 'k' .
. :
for ( k = 0; k < verts.Num(); k++ ) {

3. .
bool idMatX::IsOrthonormal( const float epsilon ) const {
...
for ( int i = 0; i < numRows; i++ ) {
...
for ( i = 1; i < numRows; i++ ) {
...
}
if ( idMath::Fabs( sum ) > epsilon ) {
return false;
}
}
return true;
}
PVS-Studio: V535 The variable 'i' is being used for this loop and for the
outer loop. idLib matrix.cpp 3128
, .
: i < numRows. ,
. ,
.

4. .
int idFileSystemLocal::ListOSFiles(...)
{
...
dir_cache_index = (++dir_cache_index) % MAX_CACHED_DIRS;
...

}
PVS-Studio: V567 Undefined behavior. The 'dir_cache_index' variable is
modified while being used twice between sequence points. TypeInfo filesystem.cpp 1877
"dir_cache_index" . ,
, .
:
A = dir_cache_index;
A = A + 1;
B = A % MAX_CACHED_DIRS;
dir_cache_index = B;
dir_cache_index = A;
, , . .
, .
:
dir_cache_index = (dir_cache_index + 1) % MAX_CACHED_DIRS;

5. .
void idMegaTexture::GenerateMegaMipMaps() {
...
byte *newBlock = (byte *)_alloca( tileSize );
...
memset( newBlock, 0, sizeof( newBlock ) );
...
}
PVS-Studio: V579 The memset function receives the pointer and its size
as arguments. It is possibly a mistake. Inspect the third argument. DoomDLL megatexture.cpp 542
'newBlock'. , .
, :
byte newBlock[ CONST_ARRAY_SIZE ];
...
memset( newBlock, 0, sizeof( newBlock ) );
'newBlock' .
. :

memset( newBlock, 0, tileSize );

6. .
void Sys_GetCurrentMemoryStatus( sysMemoryStats_t &stats ) {
...
memset( &statex, sizeof( statex ), 0 );
...
}
PVS-Studio: V575 The 'memset' function processes '0' elements. Inspect
the third argument. DoomDLL win_shared.cpp 177
'memset' . 0 .
. .
:
memset( &statex, 0, sizeof( statex ) );

7. , Copy-Paste.
void idAASFileLocal::DeleteClusters( void ) {
...
memset( &portal, 0, sizeof( portal ) );
portals.Append( portal );

memset( &cluster, 0, sizeof( portal ) );


clusters.Append( cluster );
}
PVS-Studio: V512 A call of the 'memset' function will lead to underflow of
the buffer '& cluster'. DoomDLL aasfile.cpp 1312
, . ,
Copy-Paste.
. 'portal' 'cluster'.
. :
memset( &cluster, 0, sizeof( cluster ) );
"" , .

8. .
void idBrushBSP::FloodThroughPortals_r(idBrushBSPNode *node, ...)
{
...
if ( node->occupied ) {
common->Error( "FloodThroughPortals_r: node already occupied\n" );
}
if ( !node ) {
common->Error( "FloodThroughPortals_r: NULL node\n" );
}
...
}
PVS-Studio: V595 The 'node' pointer was utilized before it was verified
against nullptr. Check lines: 1421, 1424. DoomDLL brushbsp.cpp 1421
'node' : node->occupied. , ,
NULL. . , ,
. , :
if ( node && node->occupied ) {

9. .
struct gameVersion_s {
gameVersion_s( void )
{
sprintf(string, "%s.%d%s %s %s",
ENGINE_VERSION, BUILD_NUMBER, BUILD_DEBUG,
BUILD_STRING, __DATE__, __TIME__ );
}
char string[256];
} gameVersion;
PVS-Studio: V576 Incorrect format. A different number of actual
arguments is expected while calling 'sprintf' function. Expected: 7. Present: 8. Game syscvar.cpp 54
, '__TIME__' .

10. , .
, , ,
. .
static bool R_ClipLineToLight(..., const idPlane frustum[4], ...)
{
...
for ( j = 0 ; j < 6 ; j++ ) {
d1 = frustum[j].Distance( p1 );
d2 = frustum[j].Distance( p2 );
...
}
...
}
, , 'frustum' 4 .
6 . 'R_ClipLineToLight', 6
. , .

, , PVS-Studio. , ,
, ,
PVS-Studio id Software.
.
, , . PVS-Studio
4.50, ,
Clang, Visual C++. .
, Visual C++ Doom 3
26 . Clang - 16 . , ,
.
.
, Visual C++. Clang
, Windows-.
80% .