mirror of
https://github.com/libretro/libretro-tyrquake.git
synced 2024-11-28 02:30:51 +00:00
trivial: remove unnecessary snprintf buffer termination checks
Lost my mind for a while there - snprintf always terminates the buffer. A couple of minor tidy ups in nearby code while I was looking over all the calls. Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
This commit is contained in:
parent
ee389ca9a3
commit
92adc9f0c7
@ -237,7 +237,7 @@ CL_ParseServerInfo(void)
|
||||
{
|
||||
char *level;
|
||||
const char *mapname;
|
||||
int i, len, maxlen;
|
||||
int i, maxlen;
|
||||
int nummodels, numsounds;
|
||||
char model_precache[MAX_MODELS][MAX_QPATH];
|
||||
char sound_precache[MAX_SOUNDS][MAX_QPATH];
|
||||
@ -270,9 +270,7 @@ CL_ParseServerInfo(void)
|
||||
// parse signon message
|
||||
level = cl.levelname;
|
||||
maxlen = sizeof(cl.levelname);
|
||||
len = snprintf(level, maxlen, "%s", MSG_ReadString());
|
||||
if (len > maxlen - 1)
|
||||
level[maxlen - 1] = 0;
|
||||
snprintf(level, maxlen, "%s", MSG_ReadString());
|
||||
|
||||
// seperate the printfs so the server message can have a color
|
||||
Con_Printf("\n\n\35\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36"
|
||||
@ -299,9 +297,7 @@ CL_ParseServerInfo(void)
|
||||
}
|
||||
model = model_precache[nummodels];
|
||||
maxlen = sizeof(model_precache[0]);
|
||||
len = snprintf(model, maxlen, "%s", in);
|
||||
if (len > maxlen - 1)
|
||||
model[maxlen - 1] = 0;
|
||||
snprintf(model, maxlen, "%s", in);
|
||||
Mod_TouchModel(model);
|
||||
}
|
||||
|
||||
@ -319,9 +315,7 @@ CL_ParseServerInfo(void)
|
||||
}
|
||||
sound = sound_precache[numsounds];
|
||||
maxlen = sizeof(sound_precache[0]);
|
||||
len = snprintf(sound, maxlen, "%s", in);
|
||||
if (len > maxlen - 1)
|
||||
sound[maxlen - 1] = 0;
|
||||
snprintf(sound, maxlen, "%s", in);
|
||||
S_TouchSound(sound);
|
||||
}
|
||||
|
||||
@ -838,7 +832,7 @@ CL_ParseServerMessage(void)
|
||||
{
|
||||
int cmd;
|
||||
char *s;
|
||||
int i, len;
|
||||
int i;
|
||||
byte colors;
|
||||
|
||||
//
|
||||
@ -935,9 +929,7 @@ CL_ParseServerMessage(void)
|
||||
if (i >= MAX_LIGHTSTYLES)
|
||||
Sys_Error("svc_lightstyle > MAX_LIGHTSTYLES");
|
||||
s = MSG_ReadString();
|
||||
len = snprintf(cl_lightstyle[i].map, MAX_STYLESTRING, "%s", s);
|
||||
if (len > MAX_STYLESTRING - 1)
|
||||
cl_lightstyle[i].map[MAX_STYLESTRING - 1] = 0;
|
||||
snprintf(cl_lightstyle[i].map, MAX_STYLESTRING, "%s", s);
|
||||
cl_lightstyle[i].length = strlen(cl_lightstyle[i].map);
|
||||
break;
|
||||
|
||||
@ -956,9 +948,7 @@ CL_ParseServerMessage(void)
|
||||
if (i >= cl.maxclients)
|
||||
Host_Error("%s: svc_updatename > MAX_SCOREBOARD", __func__);
|
||||
s = MSG_ReadString();
|
||||
len = snprintf(cl.players[i].name, MAX_SCOREBOARDNAME, "%s", s);
|
||||
if (len > MAX_SCOREBOARDNAME - 1)
|
||||
cl.players[i].name[MAX_SCOREBOARDNAME - 1] = 0;
|
||||
snprintf(cl.players[i].name, MAX_SCOREBOARDNAME, "%s", s);
|
||||
break;
|
||||
|
||||
case svc_updatefrags:
|
||||
|
@ -1120,13 +1120,8 @@ _Datagram_SearchForHosts(qboolean xmit, net_landriver_t *driver)
|
||||
// add it
|
||||
hostCacheCount++;
|
||||
|
||||
len = snprintf(host->name, sizeof(host->name), "%s", MSG_ReadString());
|
||||
if (len > sizeof(host->name) - 1)
|
||||
host->name[sizeof(host->name) - 1] = 0;
|
||||
len = snprintf(host->map, sizeof(host->map), "%s", MSG_ReadString());
|
||||
if (len > sizeof(host->map) - 1)
|
||||
host->map[sizeof(host->map) - 1] = 0;
|
||||
|
||||
snprintf(host->name, sizeof(host->name), "%s", MSG_ReadString());
|
||||
snprintf(host->map, sizeof(host->map), "%s", MSG_ReadString());
|
||||
host->users = MSG_ReadByte();
|
||||
host->maxusers = MSG_ReadByte();
|
||||
if (MSG_ReadByte() != NET_PROTOCOL_VERSION) {
|
||||
@ -1191,7 +1186,7 @@ _Datagram_Connect(char *host, net_landriver_t *driver)
|
||||
netadr_t readaddr;
|
||||
qsocket_t *sock;
|
||||
int newsock;
|
||||
int ret, len;
|
||||
int ret;
|
||||
int reps;
|
||||
double start_time;
|
||||
int control;
|
||||
@ -1310,10 +1305,7 @@ _Datagram_Connect(char *host, net_landriver_t *driver)
|
||||
|
||||
ErrorReturn:
|
||||
Con_Printf("%s\n", reason);
|
||||
len = snprintf(m_return_reason, sizeof(m_return_reason), "%s", reason);
|
||||
if (len > sizeof(m_return_reason) - 1)
|
||||
m_return_reason[sizeof(m_return_reason) - 1] = 0;
|
||||
|
||||
snprintf(m_return_reason, sizeof(m_return_reason), "%s", reason);
|
||||
NET_FreeQSocket(sock);
|
||||
ErrorReturn2:
|
||||
driver->CloseSocket(newsock);
|
||||
|
@ -541,7 +541,6 @@ CL_ParseServerData(void)
|
||||
char fn[MAX_OSPATH];
|
||||
qboolean cflag = false;
|
||||
int protover;
|
||||
int len;
|
||||
|
||||
Con_DPrintf("Serverdata packet received.\n");
|
||||
//
|
||||
@ -576,9 +575,7 @@ CL_ParseServerData(void)
|
||||
//ZOID--run the autoexec.cfg in the gamedir
|
||||
//if it exists
|
||||
if (cflag) {
|
||||
len = snprintf(fn, sizeof(fn), "%s/%s", com_gamedir, "config.cfg");
|
||||
if (len > sizeof(fn) - 1)
|
||||
fn[sizeof(fn) - 1] = 0;
|
||||
snprintf(fn, sizeof(fn), "%s/%s", com_gamedir, "config.cfg");
|
||||
if ((f = fopen(fn, "r")) != NULL) {
|
||||
fclose(f);
|
||||
Cbuf_AddText("cl_warncmd 0\n");
|
||||
@ -595,9 +592,7 @@ CL_ParseServerData(void)
|
||||
}
|
||||
// get the full level name
|
||||
str = MSG_ReadString();
|
||||
len = snprintf(cl.levelname, sizeof(cl.levelname), "%s", str);
|
||||
if (len > sizeof(cl.levelname) - 1)
|
||||
cl.levelname[sizeof(cl.levelname) - 1] = 0;
|
||||
snprintf(cl.levelname, sizeof(cl.levelname), "%s", str);
|
||||
|
||||
// get the movevars
|
||||
movevars.gravity = MSG_ReadFloat();
|
||||
@ -637,7 +632,7 @@ CL_ParseSoundlist(void)
|
||||
|
||||
char *str, *name;
|
||||
int numsounds;
|
||||
int n, len;
|
||||
int n;
|
||||
|
||||
// precache sounds
|
||||
numsounds = MSG_ReadByte();
|
||||
@ -649,9 +644,7 @@ CL_ParseSoundlist(void)
|
||||
if (numsounds == MAX_SOUNDS)
|
||||
Host_EndGame("Server sent too many sound_precache");
|
||||
name = cl.sound_name[numsounds];
|
||||
len = snprintf(name, NAMELEN, "%s", str);
|
||||
if (len > NAMELEN - 1)
|
||||
name[NAMELEN - 1] = 0;
|
||||
snprintf(name, NAMELEN, "%s", str);
|
||||
}
|
||||
|
||||
n = MSG_ReadByte();
|
||||
@ -678,7 +671,7 @@ CL_ParseModellist(void)
|
||||
const int NAMELEN = sizeof(cl.model_name[0]);
|
||||
int nummodels;
|
||||
char *str, *name;
|
||||
int n, len;
|
||||
int n;
|
||||
|
||||
// precache models and note certain default indexes
|
||||
nummodels = MSG_ReadByte();
|
||||
@ -691,9 +684,7 @@ CL_ParseModellist(void)
|
||||
if (nummodels == MAX_MODELS)
|
||||
Host_EndGame("Server sent too many model_precache");
|
||||
name = cl.model_name[nummodels];
|
||||
len = snprintf(name, NAMELEN, "%s", str);
|
||||
if (len > NAMELEN - 1)
|
||||
name[NAMELEN - 1] = 0;
|
||||
snprintf(name, NAMELEN, "%s", str);
|
||||
|
||||
if (!strcmp(name, "progs/spike.mdl"))
|
||||
cl_spikeindex = nummodels;
|
||||
@ -962,13 +953,10 @@ CL_ProcessUserinfo
|
||||
static void
|
||||
CL_ProcessUserInfo(int slot, player_info_t * player)
|
||||
{
|
||||
int len;
|
||||
char *name;
|
||||
|
||||
name = Info_ValueForKey(player->userinfo, "name");
|
||||
len = snprintf(player->name, sizeof(player->name), "%s", name);
|
||||
if (len > sizeof(player->name) - 1)
|
||||
player->name[sizeof(player->name) - 1] = 0;
|
||||
snprintf(player->name, sizeof(player->name), "%s", name);
|
||||
|
||||
player->topcolor = atoi(Info_ValueForKey(player->userinfo, "topcolor"));
|
||||
player->bottomcolor =
|
||||
@ -995,7 +983,7 @@ CL_UpdateUserinfo(void)
|
||||
{
|
||||
player_info_t *player;
|
||||
char *info;
|
||||
int slot, len;
|
||||
int slot;
|
||||
|
||||
slot = MSG_ReadByte();
|
||||
if (slot >= MAX_CLIENTS)
|
||||
@ -1005,10 +993,7 @@ CL_UpdateUserinfo(void)
|
||||
player->userid = MSG_ReadLong();
|
||||
|
||||
info = MSG_ReadString();
|
||||
len = snprintf(player->userinfo, sizeof(player->userinfo), "%s", info);
|
||||
if (len > sizeof(player->userinfo) - 1)
|
||||
player->userinfo[sizeof(player->userinfo) - 1] = 0;
|
||||
|
||||
snprintf(player->userinfo, sizeof(player->userinfo), "%s", info);
|
||||
CL_ProcessUserInfo(slot, player);
|
||||
}
|
||||
|
||||
@ -1023,20 +1008,15 @@ CL_SetInfo(void)
|
||||
char key[MAX_MSGLEN];
|
||||
char value[MAX_MSGLEN];
|
||||
player_info_t *player;
|
||||
int slot, len;
|
||||
int slot;
|
||||
|
||||
slot = MSG_ReadByte();
|
||||
if (slot >= MAX_CLIENTS)
|
||||
Host_EndGame("%s: svc_setinfo > MAX_SCOREBOARD", __func__);
|
||||
|
||||
player = &cl.players[slot];
|
||||
|
||||
len = snprintf(key, sizeof(key), "%s", MSG_ReadString());
|
||||
if (len > sizeof(key) - 1)
|
||||
key[sizeof(key) - 1] = 0;
|
||||
len = snprintf(value, sizeof(value), "%s", MSG_ReadString());
|
||||
if (len > sizeof(value) - 1)
|
||||
value[sizeof(value) - 1] = 0;
|
||||
snprintf(key, sizeof(key), "%s", MSG_ReadString());
|
||||
snprintf(value, sizeof(value), "%s", MSG_ReadString());
|
||||
|
||||
Con_DPrintf("SETINFO %s: %s=%s\n", player->name, key, value);
|
||||
|
||||
@ -1055,14 +1035,9 @@ CL_ServerInfo(void)
|
||||
{
|
||||
char key[MAX_MSGLEN];
|
||||
char value[MAX_MSGLEN];
|
||||
int len;
|
||||
|
||||
len = snprintf(key, sizeof(key), "%s", MSG_ReadString());
|
||||
if (len > sizeof(key) - 1)
|
||||
key[sizeof(key) - 1] = 0;
|
||||
len = snprintf(value, sizeof(value), "%s", MSG_ReadString());
|
||||
if (len > sizeof(value) - 1)
|
||||
value[sizeof(value) - 1] = 0;
|
||||
snprintf(key, sizeof(key), "%s", MSG_ReadString());
|
||||
snprintf(value, sizeof(value), "%s", MSG_ReadString());
|
||||
|
||||
Con_DPrintf("SERVERINFO: %s=%s\n", key, value);
|
||||
|
||||
@ -1149,7 +1124,7 @@ CL_ParseServerMessage(void)
|
||||
{
|
||||
int cmd;
|
||||
char *s;
|
||||
int i, j, len;
|
||||
int i, j;
|
||||
|
||||
received_framecount = host_framecount;
|
||||
cl.last_servermessage = realtime;
|
||||
@ -1236,9 +1211,7 @@ CL_ParseServerMessage(void)
|
||||
if (i >= MAX_LIGHTSTYLES)
|
||||
Sys_Error("svc_lightstyle > MAX_LIGHTSTYLES");
|
||||
s = MSG_ReadString();
|
||||
len = snprintf(cl_lightstyle[i].map, MAX_STYLESTRING, "%s", s);
|
||||
if (len > MAX_STYLESTRING - 1)
|
||||
cl_lightstyle[i].map[MAX_STYLESTRING - 1] = 0;
|
||||
snprintf(cl_lightstyle[i].map, MAX_STYLESTRING, "%s", s);
|
||||
cl_lightstyle[i].length = strlen(cl_lightstyle[i].map);
|
||||
break;
|
||||
|
||||
|
@ -116,10 +116,12 @@ Cbuf_AddText(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int len, maxlen;
|
||||
char *buf;
|
||||
|
||||
buf = (char *)cmd_text.data + cmd_text.cursize;
|
||||
maxlen = cmd_text.maxsize - cmd_text.cursize;
|
||||
va_start(ap, fmt);
|
||||
len = vsnprintf((char *)cmd_text.data + cmd_text.cursize, maxlen, fmt, ap);
|
||||
len = vsnprintf(buf, maxlen, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (cmd_text.cursize + len < cmd_text.maxsize)
|
||||
|
@ -1331,14 +1331,14 @@ va(const char *format, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
char *buf;
|
||||
int ret;
|
||||
int len;
|
||||
|
||||
buf = COM_GetStrBuf();
|
||||
va_start(argptr, format);
|
||||
ret = vsnprintf(buf, COM_STRBUF_LEN, format, argptr);
|
||||
len = vsnprintf(buf, COM_STRBUF_LEN, format, argptr);
|
||||
va_end(argptr);
|
||||
|
||||
if (ret >= COM_STRBUF_LEN)
|
||||
if (len > COM_STRBUF_LEN - 1)
|
||||
Con_DPrintf("%s: overflow (string truncated)\n", __func__);
|
||||
|
||||
return buf;
|
||||
|
@ -168,7 +168,7 @@ R_ReadPointFile_f(void)
|
||||
char name[MAX_OSPATH];
|
||||
|
||||
#ifdef NQ_HACK
|
||||
sprintf(name, "maps/%s.pts", sv.name);
|
||||
snprintf(name, sizeof(name), "maps/%s.pts", sv.name);
|
||||
#endif
|
||||
#ifdef QW_HACK
|
||||
snprintf(name, sizeof(name), "maps/%s.pts",
|
||||
|
@ -230,7 +230,6 @@ InitMode(vmode_t *mode, int num, int fullscreen, int width, int height)
|
||||
mode->width = width;
|
||||
mode->height = height;
|
||||
snprintf(mode->modedesc, sizeof(mode->modedesc), "%dx%d", width, height);
|
||||
mode->modedesc[sizeof(mode->modedesc) - 1] = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -631,8 +631,7 @@ InitWindowedMode(vmode_t *mode, int num, int width, int height)
|
||||
mode->type = MS_WINDOWED;
|
||||
mode->width = width;
|
||||
mode->height = height;
|
||||
snprintf(mode->modedesc, 13, "%dx%d", width, height);
|
||||
mode->modedesc[12] = 0;
|
||||
snprintf(mode->modedesc, sizeof(mode->modedesc), "%dx%d", width, height);
|
||||
mode->mode13 = 0;
|
||||
mode->modenum = num;
|
||||
mode->stretched = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user