From 66a046a809f07e35e3f2fc9358c41755d7b9b7b7 Mon Sep 17 00:00:00 2001 From: sezero Date: Sat, 6 Mar 2010 21:03:03 +0000 Subject: [PATCH] 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 --- quakespasm/Quake/net_dgrm.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/quakespasm/Quake/net_dgrm.c b/quakespasm/Quake/net_dgrm.c index 470d76fa..7e48a8bf 100644 --- a/quakespasm/Quake/net_dgrm.c +++ b/quakespasm/Quake/net_dgrm.c @@ -512,21 +512,26 @@ void NET_Stats_f (void) // 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) - return; - if ((host = Q_strrchr(host, ':')) != NULL) + return host; + 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; - *host++ = '\0'; - port = Q_atoi(host); - if (port > 0 && port < 65536 && port != net_hostport) - { - net_hostport = port; - Con_Printf("Port set to %d\n", net_hostport); - } + net_hostport = port; + Con_Printf("Port set to %d\n", net_hostport); } + return noport; } static qboolean testInProgress = false; @@ -604,8 +609,7 @@ static void Net_Test_f (void) if (testInProgress) return; - host = Cmd_Argv (1); - Strip_Port (host); + host = Strip_Port (Cmd_Argv(1)); if (host && hostCacheCount) { @@ -736,8 +740,7 @@ static void Test2_f (void) if (test2InProgress) return; - host = Cmd_Argv (1); - Strip_Port (host); + host = Strip_Port (Cmd_Argv(1)); if (host && hostCacheCount) { @@ -1406,7 +1409,7 @@ qsocket_t *Datagram_Connect (char *host) { qsocket_t *ret = NULL; - Strip_Port (host); + host = Strip_Port (host); for (net_landriverlevel = 0; net_landriverlevel < net_numlandrivers; net_landriverlevel++) if (net_landrivers[net_landriverlevel].initialized) if ((ret = _Datagram_Connect (host)) != NULL)