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/Ship.cpp | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'Stars45/Ship.cpp') 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); } -- cgit v1.1