From c45ce5cc4e54bdae2fd45a130d8957ec55b51b1b Mon Sep 17 00:00:00 2001 From: "FWoltermann@gmail.com" Date: Fri, 9 Dec 2011 14:12:12 +0000 Subject: A few fixes recommended by PVS Studio --- Stars45/CampaignMissionFighter.cpp | 2 +- Stars45/CampaignMissionStarship.cpp | 4 ++-- Stars45/CampaignPlanMovement.cpp | 4 ++-- Stars45/RadioHandler.cpp | 5 +---- Stars45/Ship.cpp | 4 ++-- Stars45/Sim.cpp | 20 ++++++++++---------- nGenEx/AviFile.h | 24 ++++++++++++------------ nGenEx/Font.cpp | 5 ++--- nGenEx/Game.cpp | 4 +--- nGenEx/Polygon.cpp | 1 - nGenEx/VideoDX9.cpp | 26 +++++++++----------------- 11 files changed, 42 insertions(+), 57 deletions(-) diff --git a/Stars45/CampaignMissionFighter.cpp b/Stars45/CampaignMissionFighter.cpp index f859ad8..bbb2d43 100644 --- a/Stars45/CampaignMissionFighter.cpp +++ b/Stars45/CampaignMissionFighter.cpp @@ -620,7 +620,7 @@ CampaignMissionFighter::CreateSingleElement(CombatGroup* g, CombatUnit* u) Instruction* obj = new(__FILE__,__LINE__) Instruction(Instruction::VECTOR, dst + "-" + src); elem->AddObjective(obj); } - else if (u->Type() & Ship::STARSHIPS != 0) { + else if ((u->Type() & Ship::STARSHIPS) != 0) { elem->SetMissionRole(Mission::FLEET); } diff --git a/Stars45/CampaignMissionStarship.cpp b/Stars45/CampaignMissionStarship.cpp index 184ad00..74eb2be 100644 --- a/Stars45/CampaignMissionStarship.cpp +++ b/Stars45/CampaignMissionStarship.cpp @@ -875,7 +875,7 @@ CampaignMissionStarship::CreateTargetsCarrier() RandomDirection() * Random( 50e3, 100e3); - int ntargets = 2 + RandomChance() ? 1 : 0; + int ntargets = 2 + (RandomChance() ? 1 : 0); int ntries = 8; while (ntargets > 0 && ntries > 0) { @@ -932,7 +932,7 @@ CampaignMissionStarship::CreateTargetsPatrol() elem->AddNavPoint(n); } - int ntargets = 2 + RandomChance() ? 1 : 0; + int ntargets = 2 + (RandomChance() ? 1 : 0); int ntries = 8; while (ntargets > 0 && ntries > 0) { diff --git a/Stars45/CampaignPlanMovement.cpp b/Stars45/CampaignPlanMovement.cpp index dc08798..1333503 100644 --- a/Stars45/CampaignPlanMovement.cpp +++ b/Stars45/CampaignPlanMovement.cpp @@ -136,7 +136,7 @@ CampaignPlanMovement::MoveUnit(CombatUnit* u) if (unit->GetCombatGroup() != u->GetCombatGroup() && unit->GetRegion() == u->GetRegion() && !unit->IsDropship()) { Point delta = loc - unit->Location(); - double dist = delta.Normalize(); + dist = delta.Normalize(); if (dist < closest_dist) { closest_unit = unit; @@ -147,7 +147,7 @@ CampaignPlanMovement::MoveUnit(CombatUnit* u) if (closest_unit && closest_dist < MIN_DIST) { Point delta = loc - closest_unit->Location(); - double dist = delta.Normalize(); + dist = delta.Normalize(); loc += delta * 1.1 * (MIN_DIST - closest_dist); diff --git a/Stars45/RadioHandler.cpp b/Stars45/RadioHandler.cpp index e56c850..d6397fc 100644 --- a/Stars45/RadioHandler.cpp +++ b/Stars45/RadioHandler.cpp @@ -71,10 +71,7 @@ RadioHandler::ProcessMessage(RadioMessage* msg, Ship* s) if (msg->Action() == RadioMessage::SKIP_NAVPOINT && !respond) ProcessMessageAction(msg, s); - if (ProcessMessageOrders(msg, s)) - respond = respond && true; - - else + if (!ProcessMessageOrders(msg, s)) respond = respond && ProcessMessageAction(msg, s); return respond; diff --git a/Stars45/Ship.cpp b/Stars45/Ship.cpp index f2ded5a..50555d2 100644 --- a/Stars45/Ship.cpp +++ b/Stars45/Ship.cpp @@ -4895,7 +4895,7 @@ Ship::ExecMaintFrame(double seconds) if (pwr != src) { List xfer; - for (int j = 0; j < pwr->Clients().size(); i++) { + for (int j = 0; j < pwr->Clients().size(); j++) { System* s = pwr->Clients().at(j); if (s->GetSourceIndex() == isrc) { @@ -4903,7 +4903,7 @@ Ship::ExecMaintFrame(double seconds) } } - for (int j = 0; j < xfer.size(); i++) { + for (int j = 0; j < xfer.size(); j++) { System* s = xfer.at(j); pwr->RemoveClient(s); src->AddClient(s); diff --git a/Stars45/Sim.cpp b/Stars45/Sim.cpp index b054b72..978ad6a 100644 --- a/Stars45/Sim.cpp +++ b/Stars45/Sim.cpp @@ -103,16 +103,16 @@ public: class SimSplash { public: - SimSplash(SimRegion* r, const Point& l, double d, double n) - : rgn(r), loc(l), damage(d), range(n), - owner_name("Collateral Damage"), missile(false) { } - - SimRegion* rgn; - Point loc; - double damage; - double range; - Text owner_name; - bool missile; + SimSplash(SimRegion* r, const Point& l, double d, double n) + : rgn(r), loc(l), damage(d), range(n), + owner_name("Collateral Damage"), missile(false) { } + + Text owner_name; + Point loc; + double damage; + double range; + SimRegion* rgn; + bool missile; }; // +--------------------------------------------------------------------+ diff --git a/nGenEx/AviFile.h b/nGenEx/AviFile.h index 495693a..6421504 100644 --- a/nGenEx/AviFile.h +++ b/nGenEx/AviFile.h @@ -43,18 +43,18 @@ public: HRESULT GetFrame(double seconds, Bitmap& bmp); private: - Text filename; - Rect rect; - int fps; - bool play; - - IAVIFile* pfile; // created by CreateAvi - IAVIStream* ps; - IAVIStream* ps_comp; // video stream, when first created - DWORD frame_size; // total bytes per frame of video - DWORD nframe; // which frame will be added next - DWORD nsamp; // which sample will be added next - bool iserr; // if true, then no function will do anything + Rect rect; + Text filename; + int fps; + + IAVIFile* pfile; // created by CreateAvi + IAVIStream* ps; + IAVIStream* ps_comp; // video stream, when first created + DWORD frame_size; // total bytes per frame of video + DWORD nframe; // which frame will be added next + DWORD nsamp; // which sample will be added next + bool play; + bool iserr; // if true, then no function will do anything }; // +--------------------------------------------------------------------+ diff --git a/nGenEx/Font.cpp b/nGenEx/Font.cpp index 04127c6..02dca6a 100644 --- a/nGenEx/Font.cpp +++ b/nGenEx/Font.cpp @@ -416,7 +416,7 @@ Font::FindEdges(BYTE c, double* l, double* r) static bool nokern(char c) { - if (c <= Font::ARROW_RIGHT || c >= 128) + if (c <= Font::ARROW_RIGHT) return true; const char* nokernchars = "0123456789+=<>-.,:;?'\""; @@ -917,14 +917,13 @@ Font::DrawTextMulti(const char* text, int count, const Rect& text_rect, Rect& cl else if (flags & DT_CENTER) align = DT_CENTER; - int nlines = 1; int max_width = 0; int line_start = 0; int count_remaining = count; int xoffset = 0; int yoffset = 0; - nlines = 0; + int nlines = 0; // repeat for each line of text: while (count_remaining > 0) { diff --git a/nGenEx/Game.cpp b/nGenEx/Game.cpp index f297955..8c20432 100644 --- a/nGenEx/Game.cpp +++ b/nGenEx/Game.cpp @@ -282,10 +282,8 @@ Game::Init(HINSTANCE hi, HINSTANCE hpi, LPSTR cmdline, int nCmdShow) if (status == OK) { Print(" Initializing content...\n"); InitContent(); - } - if (status == OK) { - Print(" Initializing game...\n"); + Print(" Initializing game...\n"); if (!InitGame()) { if (!panicbuf[0]) Panic("Could not initialize the game."); diff --git a/nGenEx/Polygon.cpp b/nGenEx/Polygon.cpp index d5c581f..1dc1326 100644 --- a/nGenEx/Polygon.cpp +++ b/nGenEx/Polygon.cpp @@ -64,7 +64,6 @@ VertexSet::Resize(int m, bool preserve) if (!loc || !nrm || !s_loc || !rw || !tu || !tv || !diffuse || !specular) { nverts = 0; - nverts = 0; delete [] loc; delete [] nrm; diff --git a/nGenEx/VideoDX9.cpp b/nGenEx/VideoDX9.cpp index 5b6984b..d54ae1e 100644 --- a/nGenEx/VideoDX9.cpp +++ b/nGenEx/VideoDX9.cpp @@ -265,6 +265,10 @@ VideoDX9::VideoDX9(const HWND& window, VideoSettings* vs) d3d = Direct3DCreate9(D3D_SDK_VERSION); dx9enum = new(__FILE__,__LINE__) VideoDX9Enum(d3d); + // DEBUG + vs->is_windowed = true; + // DEBUG + if (d3d && dx9enum) { if (vs) { dx9enum->req_fullscreen = vs->is_windowed ? false : true; @@ -3364,24 +3368,12 @@ VideoDX9::SetupPass(int pass) current_texture = texture_0; if (tex_bmp_1) { - if (strategy >= DX9_STRATEGY_BLEND) { - texture_1 = texcache->FindTexture(tex_bmp_1); - hr = d3ddevice->SetTexture(1, texture_1); - - if (tex_bmp_2) { - texture_2 = texcache->FindTexture(tex_bmp_2); - hr = d3ddevice->SetTexture(2, texture_2); - } - } + texture_1 = texcache->FindTexture(tex_bmp_1); + hr = d3ddevice->SetTexture(1, texture_1); - else { - texture_1 = texcache->FindTexture(tex_bmp_1); - hr = d3ddevice->SetTexture(1, texture_1); - - if (tex_bmp_2) { - texture_2 = texcache->FindTexture(tex_bmp_2); - hr = d3ddevice->SetTexture(2, texture_2); - } + if (tex_bmp_2) { + texture_2 = texcache->FindTexture(tex_bmp_2); + hr = d3ddevice->SetTexture(2, texture_2); } } } -- cgit v1.1