Skip to content

Commit

Permalink
revert COM_StripPort to previous dynamic version
Browse files Browse the repository at this point in the history
  • Loading branch information
timbergeron committed Sep 18, 2024
1 parent 37a4ff8 commit b8913ad
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions Quake/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1740,23 +1740,15 @@ COM_StripPort -- woods #historymenu
*/
const char* COM_StripPort (const char* str)
{
static char noport[MAX_QPATH];
char* p;

if (!str || !*str)
return str;

q_strlcpy(noport, str, sizeof(noport));

if ((p = Q_strrchr(noport, ':')) == NULL) // look for the colon in a regular address
return str;

if (strchr(p, ']')) // look for the colon after the IPv6 address
return str;

*p = '\0';

return noport;
const char* colon = strchr(str, ':');
size_t length = colon ? (colon - str) : strlen(str);
char* newStr = malloc(length + 1);
if (newStr)
{
strncpy(newStr, str, length);
newStr[length] = '\0';
}
return newStr;
}

/*
Expand Down

0 comments on commit b8913ad

Please sign in to comment.