1
0
Fork 0

Correct range checks for network protocol parameters.

Several checks were off by one, resulting in a segfault when only one
parameter was missing.
Also improve error messages, giving details about what is expected.
This commit is contained in:
ThorstenB 2017-11-19 16:27:53 +01:00
parent 27e2776890
commit 19b19f05bd

View file

@ -225,8 +225,9 @@ FGIO::parse_port_config( const string& config )
return NULL; return NULL;
} }
if (tokens.size() < 3) { if (tokens.size() < 4) {
SG_LOG( SG_IO, SG_ALERT, "Incompatible number of network arguments."); SG_LOG( SG_IO, SG_ALERT, "Too few arguments for network protocol. At least 3 arguments required. " <<
"Usage: --" << protocol << "=(file|socket|serial), (in|out|bi), hertz");
delete io; delete io;
return NULL; return NULL;
} }
@ -243,8 +244,9 @@ FGIO::parse_port_config( const string& config )
SG_LOG( SG_IO, SG_INFO, " hertz = " << hertz ); SG_LOG( SG_IO, SG_INFO, " hertz = " << hertz );
if ( medium == "serial" ) { if ( medium == "serial" ) {
if ( tokens.size() < 5) { if ( tokens.size() < 6) {
SG_LOG( SG_IO, SG_ALERT, "Incompatible number of arguments for serial communications."); SG_LOG( SG_IO, SG_ALERT, "Too few arguments for serial communications. " <<
"Usage --" << protocol << "=serial, (in|out|bi), hertz, device, baudrate");
delete io; delete io;
return NULL; return NULL;
} }
@ -273,8 +275,9 @@ FGIO::parse_port_config( const string& config )
} }
} else if ( medium == "file" ) { } else if ( medium == "file" ) {
// file name // file name
if ( tokens.size() < 4) { if ( tokens.size() < 5) {
SG_LOG( SG_IO, SG_ALERT, "Incompatible number of arguments for file I/O."); SG_LOG( SG_IO, SG_ALERT, "Too few arguments for file I/O. " <<
"Usage --" << protocol << "=file, (in|out), hertz, filename (,repeat)");
delete io; delete io;
return NULL; return NULL;
} }
@ -295,8 +298,9 @@ FGIO::parse_port_config( const string& config )
SGFile *ch = new SGFile( file, repeat ); SGFile *ch = new SGFile( file, repeat );
io->set_io_channel( ch ); io->set_io_channel( ch );
} else if ( medium == "socket" ) { } else if ( medium == "socket" ) {
if ( tokens.size() < 6) { if ( tokens.size() < 7) {
SG_LOG( SG_IO, SG_ALERT, "Incompatible number of arguments for socket communications."); SG_LOG( SG_IO, SG_ALERT, "Too few arguments for socket communications. " <<
"Usage --" << protocol << "=socket, (in|out|bi), hertz, hostname, port, (tcp|udp)");
delete io; delete io;
return NULL; return NULL;
} }