From eaa453335563d670d856da44bf4ea1f332c618a7 Mon Sep 17 00:00:00 2001 From: rhyskidd Date: Wed, 30 May 2012 13:26:32 +0000 Subject: Ensure check for NULL pointer occurs prior to use, not after --- Stars45/CampaignMissionFighter.cpp | 11 ++++++++--- Stars45/HUDView.cpp | 8 ++++---- Stars45/Mfd.cpp | 8 ++++---- Stars45/MsnEditDlg.cpp | 6 +++--- Stars45/MsnEditNavDlg.cpp | 6 +++--- Stars45/MsnPkgDlg.cpp | 8 ++++---- Stars45/MsnWepDlg.cpp | 4 ++-- Stars45/RadioTraffic.cpp | 18 ++++++++++-------- Stars45/Ship.cpp | 30 ++++++++++++++++++------------ Stars45/ShipAI.cpp | 5 +++-- Stars45/Sim.cpp | 11 +++++++---- Stars45/TacticalAI.cpp | 5 +++-- Stars45/TacticalView.cpp | 12 ++++++------ nGenEx/Joystick.cpp | 4 ++-- nGenEx/ListBox.cpp | 20 ++++++++++---------- 15 files changed, 87 insertions(+), 69 deletions(-) diff --git a/Stars45/CampaignMissionFighter.cpp b/Stars45/CampaignMissionFighter.cpp index 7475cb0..002dae7 100644 --- a/Stars45/CampaignMissionFighter.cpp +++ b/Stars45/CampaignMissionFighter.cpp @@ -784,13 +784,18 @@ CampaignMissionFighter::CreatePatrols() StarSystem* system = mission->GetStarSystem(); CombatGroup* base = squadron->FindCarrier(); + + if (!base) + continue; + OrbitalRegion* region = system->FindRegion(base->GetRegion()); + + if (!region) + continue; + int patrol_type = Mission::PATROL; Point base_loc; - if (!base || !region) - continue; - if (region->Type() == Orbital::TERRAIN) { patrol_type = Mission::AIR_PATROL; diff --git a/Stars45/HUDView.cpp b/Stars45/HUDView.cpp index 1aaaf96..48953ac 100644 --- a/Stars45/HUDView.cpp +++ b/Stars45/HUDView.cpp @@ -1,6 +1,6 @@ /* Project Starshatter 4.5 Destroyer Studios LLC - Copyright © 1997-2004. All Rights Reserved. + Copyright (C) 1997-2004. All Rights Reserved. SUBSYSTEM: Stars.exe FILE: HUDView.cpp @@ -1116,9 +1116,9 @@ HUDView::DrawContact(Contact* contact, int index) Point delta_v; if (c_ship) - delta_v = ship->Velocity() - c_ship->Velocity(); - else - delta_v = ship->Velocity() - c_shot->Velocity(); + delta_v = ship->Velocity() - c_ship->Velocity(); + else if (c_shot) + delta_v = ship->Velocity() - c_shot->Velocity(); if (delta_v * ship->Velocity() < 0) // losing ground closing = '-'; diff --git a/Stars45/Mfd.cpp b/Stars45/Mfd.cpp index d701e03..3ba38ae 100644 --- a/Stars45/Mfd.cpp +++ b/Stars45/Mfd.cpp @@ -1,6 +1,6 @@ /* Project Starshatter 5.0 Destroyer Studios LLC - Copyright © 1997-2007. All Rights Reserved. + Copyright (C) 1997-2007. All Rights Reserved. SUBSYSTEM: Stars.exe FILE: MFD.cpp @@ -1156,10 +1156,10 @@ MFD::DrawStatusMFD() int row = 0; char txt[32]; - if (status_rect.y > 320 && !ship->IsStarship()) - status_rect.y += 32; + if (ship) { + if (status_rect.y > 320 && !ship->IsStarship()) + status_rect.y += 32; - if (ship) { Drive* drive = ship->GetDrive(); if (drive) { DrawMFDText(row++, Game::GetText("MFD.status.THRUST").data(), status_rect, DT_LEFT); diff --git a/Stars45/MsnEditDlg.cpp b/Stars45/MsnEditDlg.cpp index f81b6c3..ed8f912 100644 --- a/Stars45/MsnEditDlg.cpp +++ b/Stars45/MsnEditDlg.cpp @@ -1,6 +1,6 @@ /* Project Starshatter 5.0 Destroyer Studios LLC - Copyright © 1997-2007. All Rights Reserved. + Copyright (C) 1997-2007. All Rights Reserved. SUBSYSTEM: Stars.exe FILE: MsnEditDlg.cpp @@ -478,10 +478,10 @@ MsnEditDlg::ScrapeForm() Galaxy* galaxy = Galaxy::GetInstance(); StarSystem* system = 0; - if (galaxy) + if (galaxy && cmb_system) system = galaxy->GetSystem(cmb_system->GetSelectedItem()); - if (cmb_system && system) { + if (system) { mission->ClearSystemList(); mission->SetStarSystem(system); diff --git a/Stars45/MsnEditNavDlg.cpp b/Stars45/MsnEditNavDlg.cpp index 5c71757..5be7807 100644 --- a/Stars45/MsnEditNavDlg.cpp +++ b/Stars45/MsnEditNavDlg.cpp @@ -1,6 +1,6 @@ /* Project Starshatter 4.5 Destroyer Studios LLC - Copyright © 1997-2004. All Rights Reserved. + Copyright (C) 1997-2004. All Rights Reserved. SUBSYSTEM: Stars.exe FILE: MsnEditNavDlg.cpp @@ -174,10 +174,10 @@ MsnEditNavDlg::ScrapeForm() Galaxy* galaxy = Galaxy::GetInstance(); StarSystem* system = 0; - if (galaxy) + if (galaxy && cmb_system) system = galaxy->GetSystem(cmb_system->GetSelectedItem()); - if (cmb_system && system) { + if (system) { mission->ClearSystemList(); mission->SetStarSystem(system); diff --git a/Stars45/MsnPkgDlg.cpp b/Stars45/MsnPkgDlg.cpp index 4d996bc..bfe8a6c 100644 --- a/Stars45/MsnPkgDlg.cpp +++ b/Stars45/MsnPkgDlg.cpp @@ -1,6 +1,6 @@ /* Project Starshatter 5.0 Destroyer Studios LLC - Copyright © 1997-2007. All Rights Reserved. + Copyright (C) 1997-2007. All Rights Reserved. SUBSYSTEM: Stars.exe FILE: MsnPkgDlg.cpp @@ -205,13 +205,13 @@ MsnPkgDlg::DrawThreats() if (!mission) return; MissionElement* player = mission->GetPlayer(); + + if (!player) return; + Text rgn0 = player->Region(); Text rgn1; int iff = player->GetIFF(); - if (!player) - return; - ListIter nav = player->NavList(); while (++nav) { if (rgn0 != nav->RegionName()) diff --git a/Stars45/MsnWepDlg.cpp b/Stars45/MsnWepDlg.cpp index 4090372..d35365b 100644 --- a/Stars45/MsnWepDlg.cpp +++ b/Stars45/MsnWepDlg.cpp @@ -1,6 +1,6 @@ /* Project Starshatter 4.5 Destroyer Studios LLC - Copyright © 1997-2004. All Rights Reserved. + Copyright (C) 1997-2004. All Rights Reserved. SUBSYSTEM: Stars.exe FILE: MsnWepDlg.cpp @@ -208,7 +208,7 @@ MsnWepDlg::SetupControls() } } - if (lbl_weight) { + if (lbl_weight && design) { if (loaded_mass < 1) loaded_mass = design->mass; diff --git a/Stars45/RadioTraffic.cpp b/Stars45/RadioTraffic.cpp index b5caba0..d87ed2f 100644 --- a/Stars45/RadioTraffic.cpp +++ b/Stars45/RadioTraffic.cpp @@ -1,6 +1,6 @@ /* Project Starshatter 4.5 Destroyer Studios LLC - Copyright © 1997-2004. All Rights Reserved. + Copyright (C) 1997-2004. All Rights Reserved. SUBSYSTEM: Stars.exe FILE: RadioTraffic.cpp @@ -371,14 +371,16 @@ RadioTraffic::DisplayMessage(RadioMessage* msg) RadioVox* vox = new(__FILE__,__LINE__) RadioVox(vox_channel, path[vox_channel], txt_buf); - vox->AddPhrase(dst_buf); - vox->AddPhrase(src_buf); - vox->AddPhrase(act_buf); + if (vox) { + vox->AddPhrase(dst_buf); + vox->AddPhrase(src_buf); + vox->AddPhrase(act_buf); - if (vox && !vox->Start()) { - RadioView::Message(txt_buf); - delete vox; - } + if (!vox->Start()) { + RadioView::Message(txt_buf); + delete vox; + } + } } // +----------------------------------------------------------------------+ diff --git a/Stars45/Ship.cpp b/Stars45/Ship.cpp index 690e54c..9063d01 100644 --- a/Stars45/Ship.cpp +++ b/Stars45/Ship.cpp @@ -1,6 +1,6 @@ /* Project Starshatter 5.0 Destroyer Studios LLC - Copyright © 1997-2007. All Rights Reserved. + Copyright (C) 1997-2007. All Rights Reserved. SUBSYSTEM: Stars.exe FILE: Ship.cpp @@ -2119,12 +2119,15 @@ Ship::CommandMode() if (!dir || dir->Type() != ShipCtrl::DIR_TYPE) { const char* msg = "Captain on the bridge"; RadioVox* vox = new(__FILE__,__LINE__) RadioVox(0, "1", msg); - vox->AddPhrase(msg); + + if (vox) { + vox->AddPhrase(msg); - if (vox && !vox->Start()) { - RadioView::Message( RadioTraffic::TranslateVox(msg) ); - delete vox; - } + if (!vox->Start()) { + RadioView::Message( RadioTraffic::TranslateVox(msg) ); + delete vox; + } + } SetControls(sim->GetControls()); } @@ -2132,12 +2135,15 @@ Ship::CommandMode() else { const char* msg = "Exec, you have the conn"; RadioVox* vox = new(__FILE__,__LINE__) RadioVox(0, "1", msg); - vox->AddPhrase(msg); - - if (vox && !vox->Start()) { - RadioView::Message( RadioTraffic::TranslateVox(msg) ); - delete vox; - } + + if (vox) { + vox->AddPhrase(msg); + + if (!vox->Start()) { + RadioView::Message( RadioTraffic::TranslateVox(msg) ); + delete vox; + } + } SetControls(0); } diff --git a/Stars45/ShipAI.cpp b/Stars45/ShipAI.cpp index f64f8bc..27e12d3 100644 --- a/Stars45/ShipAI.cpp +++ b/Stars45/ShipAI.cpp @@ -1,6 +1,6 @@ /* Project Starshatter 5.0 Destroyer Studios LLC - Copyright © 1997-2007. All Rights Reserved. + Copyright (C) 1997-2007. All Rights Reserved. SUBSYSTEM: Stars.exe FILE: ShipAI.cpp @@ -104,7 +104,8 @@ ShipAI::SetWard(Ship* s) if (s == ship->GetWard()) return; - ship->SetWard(s); + if (ship) + ship->SetWard(s); Point form = RandomDirection(); form.SwapYZ(); diff --git a/Stars45/Sim.cpp b/Stars45/Sim.cpp index e5482da..6d1f0fc 100644 --- a/Stars45/Sim.cpp +++ b/Stars45/Sim.cpp @@ -1,6 +1,6 @@ /* Project Starshatter 5.0 Destroyer Studios LLC - Copyright © 1997-2007. All Rights Reserved. + Copyright (C) 1997-2007. All Rights Reserved. SUBSYSTEM: Stars.exe FILE: Sim.cpp @@ -2733,11 +2733,14 @@ SimRegion::DamageShips() // then delete the ship: if (ship_destroyed) { NetUtil::SendObjKill(ship, owner, shot->IsMissile() ? NetObjKill::KILL_SECONDARY : NetObjKill::KILL_PRIMARY); - + Director* director; + Print(" %s Killed %s (%s)\n", owner_name, ship->Name(), FormatGameTime()); - // alert the killer - Director* director = owner->GetDirector(); + if (owner) + director = owner->GetDirector(); + + // alert the killer if (director && director->Type() > SteerAI::SEEKER && director->Type() < SteerAI::GROUND) { ShipAI* shipAI = (ShipAI*) director; shipAI->Splash(ship); diff --git a/Stars45/TacticalAI.cpp b/Stars45/TacticalAI.cpp index e8bc09b..32d364a 100644 --- a/Stars45/TacticalAI.cpp +++ b/Stars45/TacticalAI.cpp @@ -1,6 +1,6 @@ /* Project Starshatter 4.5 Destroyer Studios LLC - Copyright © 1997-2004. All Rights Reserved. + Copyright (C) 1997-2004. All Rights Reserved. SUBSYSTEM: Stars.exe FILE: TacticalAI.cpp @@ -194,7 +194,8 @@ TacticalAI::CheckObjectives() bool TacticalAI::ProcessOrders() { - ship_ai->ClearPatrol(); + if (ship_ai) + ship_ai->ClearPatrol(); if (orders && orders->EMCON() > 0) { int desired_emcon = orders->EMCON(); diff --git a/Stars45/TacticalView.cpp b/Stars45/TacticalView.cpp index 2245691..c6550d0 100644 --- a/Stars45/TacticalView.cpp +++ b/Stars45/TacticalView.cpp @@ -1,6 +1,6 @@ /* Project Starshatter 5.0 Destroyer Studios LLC - Copyright © 1997-2007. All Rights Reserved. + Copyright (C) 1997-2007. All Rights Reserved. SUBSYSTEM: Stars.exe FILE: TacticalView.cpp @@ -261,13 +261,13 @@ TacticalView::DrawMouseRect() void TacticalView::DrawSelection(Ship* seln) { + if (!seln) + return; + Graphic* g = seln->Rep(); Rect r = g->ScreenRect(); - - Point mark_pt; - - if (seln) - mark_pt = seln->Location(); + + Point mark_pt = seln->Location(); projector->Transform(mark_pt); diff --git a/nGenEx/Joystick.cpp b/nGenEx/Joystick.cpp index af11e69..97dc671 100644 --- a/nGenEx/Joystick.cpp +++ b/nGenEx/Joystick.cpp @@ -1,6 +1,6 @@ /* Project nGenEx Destroyer Studios LLC - Copyright © 1997-2004. All Rights Reserved. + Copyright (C) 1997-2004. All Rights Reserved. SUBSYSTEM: nGenEx.lib FILE: Joystick.cpp @@ -542,7 +542,7 @@ Joystick::Acquire() if (ndev < 1) EnumerateDevices(); - if (CreateDevice(select)) + if (CreateDevice(select) && pdev) pdev->Acquire(); } diff --git a/nGenEx/ListBox.cpp b/nGenEx/ListBox.cpp index 3af31cb..710bb95 100644 --- a/nGenEx/ListBox.cpp +++ b/nGenEx/ListBox.cpp @@ -1,6 +1,6 @@ /* Project nGenEx Destroyer Studios LLC - Copyright © 1997-2004. All Rights Reserved. + Copyright � 1997-2004. All Rights Reserved. SUBSYSTEM: nGenEx.lib FILE: ListBox.cpp @@ -83,10 +83,10 @@ public: int ListBoxItem::operator < (const ListBoxItem& item) const { - int sort_column = listbox->GetSortColumn() - 1; - int sort_criteria = listbox->GetSortCriteria(); + if (listbox && listbox == item.listbox) { + int sort_column = listbox->GetSortColumn() - 1; + int sort_criteria = listbox->GetSortCriteria(); - if (listbox && listbox == item.listbox) { if (sort_column == -1) { switch (sort_criteria) { case ListBox::LIST_SORT_NUMERIC_DESCENDING: @@ -130,10 +130,10 @@ int ListBoxItem::operator < (const ListBoxItem& item) const int ListBoxItem::operator <=(const ListBoxItem& item) const { - int sort_column = listbox->GetSortColumn() - 1; - int sort_criteria = listbox->GetSortCriteria(); - if (listbox && listbox == item.listbox) { + int sort_column = listbox->GetSortColumn() - 1; + int sort_criteria = listbox->GetSortCriteria(); + if (sort_column == -1) { switch (sort_criteria) { case ListBox::LIST_SORT_NUMERIC_DESCENDING: @@ -177,10 +177,10 @@ int ListBoxItem::operator <=(const ListBoxItem& item) const int ListBoxItem::operator == (const ListBoxItem& item) const { - int sort_column = listbox->GetSortColumn() - 1; - int sort_criteria = listbox->GetSortCriteria(); - if (listbox && listbox == item.listbox) { + int sort_column = listbox->GetSortColumn() - 1; + int sort_criteria = listbox->GetSortCriteria(); + if (sort_column == -1) { switch (sort_criteria) { case ListBox::LIST_SORT_NUMERIC_DESCENDING: -- cgit v1.1