Skip to content

Commit

Permalink
Merge pull request #676 from dimhotepus/pvs_studio_fixes#4
Browse files Browse the repository at this point in the history
Some PVS-Studio warning fixes (part 4)
  • Loading branch information
Xottab-DUTY committed Dec 18, 2020
2 parents 6da1907 + 8cb76cd commit 0b648a3
Show file tree
Hide file tree
Showing 32 changed files with 102 additions and 138 deletions.
4 changes: 1 addition & 3 deletions Externals/cximage/ximath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ CxRect2::CxRect2(float const x1_, float const y1_, float const x2_, float const
topRight.y=y2_;
}

CxRect2::CxRect2(CxRect2 const &p)
CxRect2::CxRect2(CxRect2 const &p) : botLeft(p.botLeft), topRight(p.topRight)
{
botLeft=p.botLeft;
topRight=p.topRight;
}

float CxRect2::Surface() const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ FCGI_FILE *FCGI_freopen(const char *path, const char *mode,
FCGI_FILE *fp)
{
if(fp->stdio_stream) {
if(freopen(path, mode, fp->stdio_stream) == NULL)
fp->stdio_stream = freopen(path, mode, fp->stdio_stream);
if(fp->stdio_stream == NULL)
return NULL;
else
return fp;
Expand Down
4 changes: 2 additions & 2 deletions src/utils/mp_gpprof_server/libraries/gamespy/GP/gpiBuddy.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ gpiProcessRecvBuddyList(
{
buffer[j] = c;
}
buffer[j] = '\0';
buffer[min(j, sizeof(buffer) - 1)] = '\0';
index += j;
}
else
Expand Down Expand Up @@ -1049,12 +1049,12 @@ gpiDeleteBuddy(
freeclear(pProfile->buddyStatusInfo->gameType);
freeclear(pProfile->buddyStatusInfo->gameVariant);
freeclear(pProfile->buddyStatusInfo->gameMapName);
freeclear(pProfile->buddyStatusInfo);
if (pProfile->buddyStatusInfo->extendedInfoKeys)
{
ArrayFree(pProfile->buddyStatusInfo->extendedInfoKeys);
pProfile->buddyStatusInfo->extendedInfoKeys = NULL;
}
freeclear(pProfile->buddyStatusInfo);

if(gpiCanFreeProfile(pProfile))
gpiRemoveProfile(connection, pProfile);
Expand Down
6 changes: 3 additions & 3 deletions src/utils/mp_gpprof_server/libraries/gamespy/GP/gpiProfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ gpiReadDiskProfile(
{
if(toupper(value[0]) == 'M')
infoCache.sex = GP_MALE;
else if(toupper(value[1] == 'F'))
else if(toupper(value[0]) == 'F')
infoCache.sex = GP_FEMALE;
else
infoCache.sex = GP_PAT;
Expand Down Expand Up @@ -1173,12 +1173,12 @@ gpiAddToBlockedList(
freeclear(profile->buddyStatusInfo->gameType);
freeclear(profile->buddyStatusInfo->gameVariant);
freeclear(profile->buddyStatusInfo->gameMapName);
freeclear(profile->buddyStatusInfo);
if (profile->buddyStatusInfo->extendedInfoKeys)
{
ArrayFree(profile->buddyStatusInfo->extendedInfoKeys);
profile->buddyStatusInfo->extendedInfoKeys = NULL;
}
freeclear(profile->buddyStatusInfo);

iconnection->profileList.numBuddies--;
assert(iconnection->profileList.numBuddies >= 0);
Expand Down Expand Up @@ -1369,7 +1369,7 @@ gpiProcessRecvBlockedList(
{
buffer[j] = c;
}
buffer[j] = '\0';
buffer[min(j, sizeof(buffer) - 1)] = '\0';
index += j;
}
else
Expand Down
2 changes: 2 additions & 0 deletions src/utils/mp_gpprof_server/libraries/gamespy/common/gsDebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ void gsDebugFormat(GSIDebugCategory theCat, GSIDebugType theType,

// Pass to VA version
gsDebugVaList(theCat, theType, theLevel, theTokenStr, aParameterList);

va_end(aParameterList);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
///////////////////////////////////////////////////////////////////////////////
int SetSockBlocking(SOCKET sock, int isblocking)
{
int rcode;
int rcode = -1;

#if defined(_REVOLUTION)
int val;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/xrMiscMath/vector3d_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Fvector cr_vectorHP(float h, float p)
return r;
}

float angle_between_vectors(Fvector const v1, Fvector const v2)
float angle_between_vectors(Fvector const& v1, Fvector const& v2)
{
float const mag1 = v1.magnitude();
float const mag2 = v2.magnitude();
Expand Down
59 changes: 31 additions & 28 deletions src/xrAICore/Components/problem_solver_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,42 +254,45 @@ IC bool CProblemSolverAbstract::is_goal_reached_impl(const _index_type& vertex_i
typename xr_vector<_operator_condition>::const_iterator E = vertex_index.conditions().end();
typename xr_vector<_operator_condition>::const_iterator i = target_state().conditions().begin();
typename xr_vector<_operator_condition>::const_iterator e = target_state().conditions().end();
typename xr_vector<_operator_condition>::const_iterator II = current_state().conditions().begin();
typename xr_vector<_operator_condition>::const_iterator EE = current_state().conditions().end();
for (; (i != e) && (I != E);)

{
if ((*I).condition() < (*i).condition())
{
++I;
}
else if ((*I).condition() > (*i).condition())
typename xr_vector<_operator_condition>::const_iterator II = current_state().conditions().begin();
typename xr_vector<_operator_condition>::const_iterator EE = current_state().conditions().end();
for (; (i != e) && (I != E);)
{
for (; (II != EE) && ((*II).condition() < (*i).condition());)
if ((*I).condition() < (*i).condition())
{
++I;
}
else if ((*I).condition() > (*i).condition())
{
for (; (II != EE) && ((*II).condition() < (*i).condition());)
++II;
if ((II == EE) || ((*II).condition() > (*i).condition()))
evaluate_condition(II, EE, (*i).condition());
if ((*II).value() != (*i).value())
return (false);
++II;
if ((II == EE) || ((*II).condition() > (*i).condition()))
evaluate_condition(II, EE, (*i).condition());
if ((*II).value() != (*i).value())
return (false);
++II;
++i;
++i;
}
else
{
if ((*I).value() != (*i).value())
return (false);
++I;
++i;
}
}
else

if (I == E)
{
if ((*I).value() != (*i).value())
return (false);
++I;
++i;
I = std::move(II);
E = std::move(EE);
}
else
return (true);
}

if (I == E)
{
I = II;
E = EE;
}
else
return (true);

for (; i != e;)
{
if ((I == E) || ((*I).condition() > (*i).condition()))
Expand Down
1 change: 1 addition & 0 deletions src/xrAICore/Navigation/level_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "xrEngine/profiler.h"

CLevelGraph::CLevelGraph(const char* fileName)
: m_level_id(GameGraph::_LEVEL_ID(-1))
{
string256 filePath;
strconcat(sizeof(filePath), filePath, fileName, LEVEL_GRAPH_NAME);
Expand Down
6 changes: 3 additions & 3 deletions src/xrAICore/Navigation/level_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ class XRAICORE_API CLevelGraph
IC void begin(const CLevelVertex& vertex, const_iterator& begin, const_iterator& end) const;
IC void begin(const CLevelVertex* vertex, const_iterator& begin, const_iterator& end) const;
IC void begin(u32 vertex_id, const_iterator& begin, const_iterator& end) const;
IC u32 value(const CLevelVertex& vertex, const_iterator& i) const;
IC u32 value(const CLevelVertex* vertex, const_iterator& i) const;
IC u32 value(const u32 vertex_id, const_iterator& i) const;
IC u32 value(const CLevelVertex& vertex, const_iterator i) const;
IC u32 value(const CLevelVertex* vertex, const_iterator i) const;
IC u32 value(const u32 vertex_id, const_iterator i) const;
IC const CHeader& header() const;
ICF bool valid_vertex_id(u32 vertex_id) const;
IC const GameGraph::_LEVEL_ID& level_id() const;
Expand Down
6 changes: 3 additions & 3 deletions src/xrAICore/Navigation/level_graph_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,9 @@ IC void CLevelGraph::begin(const u32 vertex_id, const_iterator& _begin, const_it
begin(vertex(vertex_id), _begin, end);
}

IC u32 CLevelGraph::value(const CLevelVertex& vertex, const_iterator& i) const { return (vertex.link(i)); }
IC u32 CLevelGraph::value(const CLevelVertex* vertex, const_iterator& i) const { return (value(*vertex, i)); }
IC u32 CLevelGraph::value(const u32 vertex_id, const_iterator& i) const { return (value(vertex(vertex_id), i)); }
IC u32 CLevelGraph::value(const CLevelVertex& vertex, const_iterator i) const { return (vertex.link(i)); }
IC u32 CLevelGraph::value(const CLevelVertex* vertex, const_iterator i) const { return (value(*vertex, i)); }
IC u32 CLevelGraph::value(const u32 vertex_id, const_iterator i) const { return (value(vertex(vertex_id), i)); }
IC bool CLevelGraph::is_accessible(const u32 vertex_id) const
{
return (valid_vertex_id(vertex_id) && m_access_mask[vertex_id]);
Expand Down
2 changes: 1 addition & 1 deletion src/xrAICore/Navigation/vertex_allocator_fixed_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#define CFixedVertexAllocator CVertexAllocatorFixed<ReserveSize>::CDataStorage<TCompoundVertex>

TEMPLATE_SPECIALIZATION
inline CFixedVertexAllocator::CDataStorage() { m_vertices.resize(ReserveSize); }
inline CFixedVertexAllocator::CDataStorage() : m_vertex_count(u32(-1)) { m_vertices.resize(ReserveSize); }
TEMPLATE_SPECIALIZATION
inline CFixedVertexAllocator::~CDataStorage() {}
TEMPLATE_SPECIALIZATION
Expand Down
4 changes: 1 addition & 3 deletions src/xrCDB/ISpatial_verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ class walker
u32 n_count;

public:
walker()
walker() : o_count(0), n_count(0)
{
o_count = 0;
n_count = 0;
}
void walk(ISpatial_NODE* N, Fvector& n_C, float n_R)
{
Expand Down
12 changes: 6 additions & 6 deletions src/xrCore/Crypto/trivial_encryptor.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#include "stdafx.h"
#include "trivial_encryptor.h"
#include "Math/Random32.hpp"

trivial_encryptor g_trivial_encryptor;

class random32
{
u32 m_seed;
CRandom32 generator;

public:
random32() = delete;

random32(const u32& seed)
explicit random32(u32 seed)
{
m_seed = seed;
generator.seed(seed);
}

u32 random(const u32& range)
u32 random(u32 range)
{
m_seed = 0x08088405 * m_seed + 1;
return (u32(u64(m_seed) * u64(range) >> 32));
return generator.random(range);
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/xrCore/FTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ class XRCORE_API CTimer : public CTimerBase
{
const auto delta = current - realTime;
const double deltaD = double(delta.count());
const double time = deltaD * m_time_factor + .5;
const auto result = u64(time);
const double elapsedTime = deltaD * m_time_factor + .5;
const auto result = u64(elapsedTime);
return Duration(this->time.count() + result);
}

Expand Down
6 changes: 3 additions & 3 deletions src/xrCore/Math/Random32.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ class CRandom32
u32 m_seed;

public:
inline u32 seed() { return m_seed; }
inline u32 seed() const { return m_seed; }
inline void seed(u32 seed) { m_seed = seed; }
inline u32 random(u32 range)
{
m_seed = 0x08088405 * m_seed + 1;
return u32(u64(m_seed) * u64(range) >> 32);
m_seed = 0x08088405U * m_seed + 1U;
return u32((u64(m_seed) * u64(range)) >> 32U);
}
};
2 changes: 1 addition & 1 deletion src/xrCore/_vector3d_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Fvector crossproduct(const Fvector& v1, const Fvector& v2);

Fvector cr_vectorHP(float h, float p);

float angle_between_vectors(Fvector const v1, Fvector const v2);
float angle_between_vectors(Fvector const& v1, Fvector const& v2);

Fvector rotate_point(Fvector const& point, float const angle);

Expand Down
3 changes: 2 additions & 1 deletion src/xrCore/fastdelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,8 @@ class ClosurePtr : public DelegateMemento
// Ensure that there's a compilation failure if function pointers
// and data pointers have different sizes.
// If you get this error, you need to #undef FASTDELEGATE_USESTATICFUNCTIONHACK.
typedef int ERROR_CantUseEvilMethod[sizeof(UnvoidStaticFuncPtr) == sizeof(this) ? 1 : -1];
static_assert(sizeof(UnvoidStaticFuncPtr) == sizeof(this),
"Function ptr size != data ptr size. Please #undef FASTDELEGATE_USESTATICFUNCTIONHACK");
return horrible_cast<UnvoidStaticFuncPtr>(this);
}
#endif // !defined(FASTDELEGATE_USESTATICFUNCTIONHACK)
Expand Down
20 changes: 5 additions & 15 deletions src/xrD3D9-Null/IDirect3DIndexBuffer9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,13 @@ const GUID DECLSPEC_SELECTANY IID_IDirect3DIndexBuffer9;

xrIDirect3DIndexBuffer9::xrIDirect3DIndexBuffer9(
IDirect3DDevice9* pIDirect3DDevice9, UINT iLength, DWORD iUsage, D3DFORMAT iFormat, D3DPOOL iPool)
: m_refCount(0)
: m_refCount(0), m_pIDirect3DDevice9(pIDirect3DDevice9)
//#ifdef D3D_DEBUG_INFO
, Name(nullptr), Length(iLength), Usage(iUsage), Format(iFormat), Pool(iPool),
Priority(0), LockCount(0), CreationCallStack(nullptr)
//#endif
{
APIDEBUG("xrIDirect3DIndexBuffer9::xrIDirect3DIndexBuffer9");
m_pIDirect3DDevice9 = pIDirect3DDevice9;

//#ifdef D3D_DEBUG_INFO
//-----------------------------------------------
Name = NULL;
Length = iLength;
Usage = iUsage;
Format = iFormat;
Pool = iPool;
Priority = 0;
LockCount = 0;
CreationCallStack = NULL;
//-----------------------------------------------
//#endif

switch (Format)
{
Expand Down
2 changes: 1 addition & 1 deletion src/xrEngine/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class ENGINE_API CRenderDevice : public CRenderDeviceBase, public IWindowHandler
Fmatrix mInvFullTransform;

CRenderDevice()
: fWidth_2(0), fHeight_2(0),
: dwPrecacheTotal(0), fWidth_2(0), fHeight_2(0),
mtProcessingAllowed(false), mt_bMustExit(false),
m_editor_module(nullptr), m_editor_initialize(nullptr),
m_editor_finalize(nullptr), m_editor(nullptr)
Expand Down
4 changes: 1 addition & 3 deletions src/xrGame/PHScriptCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ void CPHScriptAction::run()
bool CPHScriptAction::obsolete() const { return b_obsolete; }
/////////////////////////////////////////////////////////////////////////////////////////////
CPHScriptObjectAction::CPHScriptObjectAction(const luabind::object& lua_object, LPCSTR method)
: b_obsolete(false), m_lua_object(xr_new<luabind::object>(lua_object)), m_method_name(method)
{
b_obsolete = false;
m_lua_object = xr_new<luabind::object>(lua_object);
m_method_name = method;
}

CPHScriptObjectAction::CPHScriptObjectAction(const CPHScriptObjectAction& object)
Expand Down
21 changes: 9 additions & 12 deletions src/xrGame/Torch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,21 @@ static const float OPTIMIZATION_DISTANCE = 100.f;

static bool stalker_use_dynamic_lights = false;

CTorch::CTorch(void)
CTorch::CTorch()
: fBrightness(1.f), lanim(nullptr), guid_bone(BI_NONE),
m_delta_h(0), m_switched_on(false),
light_render(GEnv.Render->light_create()),
light_omni(GEnv.Render->light_create()),
glow_render(GEnv.Render->glow_create()),
m_bNightVisionEnabled(false), m_bNightVisionOn(false), m_night_vision(nullptr)
{
light_render = GEnv.Render->light_create();
m_prev_hp.set(0, 0);

light_render->set_type(IRender_Light::SPOT);
light_render->set_shadow(true);
light_omni = GEnv.Render->light_create();
light_omni->set_type(IRender_Light::POINT);
light_omni->set_shadow(false);

m_switched_on = false;
glow_render = GEnv.Render->glow_create();
lanim = 0;
fBrightness = 1.f;

m_prev_hp.set(0, 0);
m_delta_h = 0;
m_night_vision = NULL;

// Disabling shift by x and z axes for 1st render,
// because we don't have dynamic lighting in it.
if (GEnv.Render->GenerationIsR1())
Expand Down
Loading

0 comments on commit 0b648a3

Please sign in to comment.