From: ehofman Date: Thu, 18 Jun 2009 11:20:02 +0000 (+0000) Subject: Return an error when not enough tokens are parsed for the generic protocol, that... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=879b4df9fcd5c18dc14a314a31cffcc9c973a829;p=flightgear.git Return an error when not enough tokens are parsed for the generic protocol, that must be better than causing a segmentation fault. --- diff --git a/src/Main/fg_io.cxx b/src/Main/fg_io.cxx index a2260731e..2288fc538 100644 --- a/src/Main/fg_io.cxx +++ b/src/Main/fg_io.cxx @@ -102,6 +102,7 @@ FGIO::parse_port_config( const string& config ) return 0; } + unsigned num_tokens = tokens.size(); string protocol = tokens[0]; SG_LOG( SG_IO, SG_INFO, " protocol = " << protocol ); @@ -194,8 +195,16 @@ FGIO::parse_port_config( const string& config ) configToken = 5; else configToken = 6; - FGGeneric *generic = new FGGeneric( tokens[configToken] ); - io = generic; + if (configToken < num_tokens) + { + FGGeneric *generic = new FGGeneric( tokens[configToken] ); + io = generic; + } + else + { + SG_LOG( SG_IO, SG_ALERT, "Not enough tokens passed for the generic protocol."); + return NULL; + } } else if ( protocol == "multiplay" ) { if ( tokens.size() != 5 ) { SG_LOG( SG_IO, SG_ALERT, "Ignoring invalid --multiplay option "