actually use strtol as intended, checking for invalid inputs

This commit is contained in:
AJ Kelly
2011-03-27 19:19:31 -05:00
parent cab7c1f077
commit f4a9a3acc4
+9 -2
View File
@@ -112,9 +112,16 @@ void NetworkSyncManager::PostStartUp( const RString& ServerIP )
size_t cLoc = ServerIP.find( ':' ); size_t cLoc = ServerIP.find( ':' );
if( ServerIP.find( ':' ) != RString::npos ) if( ServerIP.find( ':' ) != RString::npos )
{ {
char* cEnd;
iPort = (unsigned short)strtol( ServerIP.substr( cLoc + 1 ).c_str(), &cEnd, 10 );
sAddress = ServerIP.substr( 0, cLoc ); sAddress = ServerIP.substr( 0, cLoc );
char* cEnd;
errno = 0;
iPort = (unsigned short)strtol( ServerIP.substr( cLoc + 1 ).c_str(), &cEnd, 10 );
if( *cEnd != 0 || errno != 0 )
{
m_startupStatus = 2;
LOG->Warn( "Invalid port" );
return;
}
} }
else else
{ {