Fix potential warning from string truncation

Also the MS seems to just throw the entire char array into the website and ignore null terminators, so I'm memsetting maptitle all to 0 before we do anything with it.
This commit is contained in:
Sryder 2018-11-18 11:05:05 +00:00
parent 0e3b225011
commit 5a96a0d0a4

View file

@ -1320,6 +1320,8 @@ static void SV_SendServerInfo(INT32 node, tic_t servertime)
else
netbuffer->u.serverinfo.iszone = 0;
memset(netbuffer->u.serverinfo.maptitle, 0, 33);
if (!(mapheaderinfo[gamemap-1]->menuflags & LF2_HIDEINMENU) && mapheaderinfo[gamemap-1]->lvlttl[0])
{
//strncpy(netbuffer->u.serverinfo.maptitle, (char *)mapheaderinfo[gamemap-1]->lvlttl, 33);
@ -1340,15 +1342,27 @@ static void SV_SendServerInfo(INT32 node, tic_t servertime)
else
{
if (mapheaderinfo[gamemap-1]->actnum[0])
snprintf(netbuffer->u.serverinfo.maptitle,
{
if (snprintf(netbuffer->u.serverinfo.maptitle,
33,
"%s %s %s",
mapheaderinfo[gamemap-1]->lvlttl, mapheaderinfo[gamemap-1]->zonttl, mapheaderinfo[gamemap-1]->actnum);
mapheaderinfo[gamemap-1]->lvlttl, mapheaderinfo[gamemap-1]->zonttl, mapheaderinfo[gamemap-1]->actnum) < 0)
{
// If there's an encoding error, send UNKNOWN, we accept that the above may be truncated
strncpy(netbuffer->u.serverinfo.maptitle, "UNKNOWN", 33);
}
}
else
snprintf(netbuffer->u.serverinfo.maptitle,
{
if (snprintf(netbuffer->u.serverinfo.maptitle,
33,
"%s %s",
mapheaderinfo[gamemap-1]->lvlttl, mapheaderinfo[gamemap-1]->zonttl);
mapheaderinfo[gamemap-1]->lvlttl, mapheaderinfo[gamemap-1]->zonttl) < 0)
{
// If there's an encoding error, send UNKNOWN, we accept that the above may be truncated
strncpy(netbuffer->u.serverinfo.maptitle, "UNKNOWN", 33);
}
}
}
}
else