net_dgrm.c (Strip_Port): rewrote it to not modify its input string and

return its own copy, which I feel safer with. Adjusted its callers.


git-svn-id: svn+ssh://svn.code.sf.net/p/quakespasm/code/trunk@105 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
sezero 2010-03-06 21:03:03 +00:00
parent 50df0eeb00
commit 66a046a809

View file

@ -512,21 +512,26 @@ void NET_Stats_f (void)
// recognize ip:port (based on ProQuake) // recognize ip:port (based on ProQuake)
static void Strip_Port (char *host) static char *Strip_Port (char *host)
{ {
static char noport[MAX_QPATH];
/* array size as in Host_Connect_f() */
char *p;
int port;
if (!host || !*host) if (!host || !*host)
return; return host;
if ((host = Q_strrchr(host, ':')) != NULL) strcpy (noport, host);
if ((p = Q_strrchr(noport, ':')) == NULL)
return host;
*p++ = '\0';
port = Q_atoi (p);
if (port > 0 && port < 65536 && port != net_hostport)
{ {
int port; net_hostport = port;
*host++ = '\0'; Con_Printf("Port set to %d\n", net_hostport);
port = Q_atoi(host);
if (port > 0 && port < 65536 && port != net_hostport)
{
net_hostport = port;
Con_Printf("Port set to %d\n", net_hostport);
}
} }
return noport;
} }
static qboolean testInProgress = false; static qboolean testInProgress = false;
@ -604,8 +609,7 @@ static void Net_Test_f (void)
if (testInProgress) if (testInProgress)
return; return;
host = Cmd_Argv (1); host = Strip_Port (Cmd_Argv(1));
Strip_Port (host);
if (host && hostCacheCount) if (host && hostCacheCount)
{ {
@ -736,8 +740,7 @@ static void Test2_f (void)
if (test2InProgress) if (test2InProgress)
return; return;
host = Cmd_Argv (1); host = Strip_Port (Cmd_Argv(1));
Strip_Port (host);
if (host && hostCacheCount) if (host && hostCacheCount)
{ {
@ -1406,7 +1409,7 @@ qsocket_t *Datagram_Connect (char *host)
{ {
qsocket_t *ret = NULL; qsocket_t *ret = NULL;
Strip_Port (host); host = Strip_Port (host);
for (net_landriverlevel = 0; net_landriverlevel < net_numlandrivers; net_landriverlevel++) for (net_landriverlevel = 0; net_landriverlevel < net_numlandrivers; net_landriverlevel++)
if (net_landrivers[net_landriverlevel].initialized) if (net_landrivers[net_landriverlevel].initialized)
if ((ret = _Datagram_Connect (host)) != NULL) if ((ret = _Datagram_Connect (host)) != NULL)