change (v)sprintf calls to (v)snprintf calls

This commit is contained in:
svdijk 2013-05-17 21:50:31 +02:00
parent be63c7f198
commit b46e210d76
16 changed files with 29 additions and 34 deletions

View file

@ -346,9 +346,9 @@ VID_CheckChanges(void)
cls.disable_screen = true; cls.disable_screen = true;
#ifdef _WIN32 #ifdef _WIN32
sprintf(name, "ref_%s.dll", vid_ref->string); snprintf(name, sizeof(name), "ref_%s.dll", vid_ref->string);
#else #else
sprintf(name, "ref_%s.so", vid_ref->string); snprintf(name, sizeof(name), "ref_%s.so", vid_ref->string);
#endif #endif
if (!VID_LoadRefresh(name)) if (!VID_LoadRefresh(name))

View file

@ -839,7 +839,7 @@ NET_Socket(char *net_interface, int port, netsrc_t type, int family)
} }
else else
{ {
sprintf(Buf, "%5d", port); snprintf(Buf, sizeof(Buf), "%5d", port);
Service = Buf; Service = Buf;
} }

View file

@ -177,7 +177,7 @@ Sys_FindFirst(char *path, unsigned musthave, unsigned canhave)
{ {
if (CompareAttributes(findbase, d->d_name, musthave, canhave)) if (CompareAttributes(findbase, d->d_name, musthave, canhave))
{ {
sprintf(findpath, "%s/%s", findbase, d->d_name); snprintf(findpath, sizeof(findpath), "%s/%s", findbase, d->d_name);
return findpath; return findpath;
} }
} }
@ -202,7 +202,7 @@ Sys_FindNext(unsigned musthave, unsigned canhave)
{ {
if (CompareAttributes(findbase, d->d_name, musthave, canhave)) if (CompareAttributes(findbase, d->d_name, musthave, canhave))
{ {
sprintf(findpath, "%s/%s", findbase, d->d_name); snprintf(findpath, sizeof(findpath), "%s/%s", findbase, d->d_name);
return findpath; return findpath;
} }
} }

View file

@ -834,7 +834,7 @@ NET_IPSocket(char *net_interface, int port, netsrc_t type, int family)
} }
else else
{ {
sprintf(Buf, "%5d", port); snprintf(Buf, sizeof(Buf), "%5d", port);
Service = Buf; Service = Buf;
} }

View file

@ -80,7 +80,7 @@ Sys_Error(char *error, ...)
Qcommon_Shutdown(); Qcommon_Shutdown();
va_start(argptr, error); va_start(argptr, error);
vsprintf(text, error, argptr); vsnprintf(text, sizeof(text), error, argptr);
va_end(argptr); va_end(argptr);
#ifndef DEDICATED_ONLY #ifndef DEDICATED_ONLY

View file

@ -742,7 +742,7 @@ Con_DrawConsole(float frac)
dlbar[i++] = '\x82'; dlbar[i++] = '\x82';
dlbar[i] = 0; dlbar[i] = 0;
sprintf(dlbar + strlen(dlbar), " %02d%%", cls.downloadpercent); snprintf(dlbar + i, sizeof(dlbar) - i, " %02d%%", cls.downloadpercent);
/* draw it */ /* draw it */
y = con.vislines - 12; y = con.vislines - 12;

View file

@ -399,7 +399,7 @@ CL_RequestNextDownload(void)
{ {
char fn[MAX_OSPATH]; char fn[MAX_OSPATH];
sprintf(fn, "textures/%s.wal", snprintf(fn, sizeof(fn), "textures/%s.wal",
map_surfaces[precache_tex++].rname); map_surfaces[precache_tex++].rname);
if (!CL_CheckOrDownloadFile(fn)) if (!CL_CheckOrDownloadFile(fn))

View file

@ -1184,7 +1184,7 @@ SCR_ExecuteLayoutString(char *s)
ping = 999; ping = 999;
} }
sprintf(block, "%3d %3d %-12.12s", score, ping, ci->name); snprintf(block, sizeof(block), "%3d %3d %-12.12s", score, ping, ci->name);
if (value == cl.playernum) if (value == cl.playernum)
{ {
@ -1508,7 +1508,7 @@ SCR_UpdateScreen(void)
if (cl_drawfps->value) if (cl_drawfps->value)
{ {
char s[8]; char s[8];
sprintf(s, "%3.0ffps", 1 / cls.frametime); snprintf(s, sizeof(s), "%3.0ffps", 1 / cls.frametime);
DrawString(viddef.width - 64, 0, s); DrawString(viddef.width - 64, 0, s);
} }

View file

@ -1100,22 +1100,16 @@ Com_sprintf(char *dest, int size, char *fmt, ...)
{ {
int len; int len;
va_list argptr; va_list argptr;
static char bigbuffer[0x10000];
va_start(argptr, fmt); va_start(argptr, fmt);
len = vsnprintf(bigbuffer, 0x10000, fmt, argptr); len = vsnprintf(dest, size, fmt, argptr);
va_end(argptr); va_end(argptr);
if ((len >= size) || (len == size)) if (len >= size)
{ {
Com_Printf("Com_sprintf: overflow\n"); Com_Printf("Com_sprintf: overflow\n");
dest = NULL;
return; return;
} }
bigbuffer[size - 1] = '\0';
strcpy(dest, bigbuffer);
} }
char * char *

View file

@ -1218,7 +1218,7 @@ Cmd_PlayerList_f(edict_t *ent)
if (strlen(text) + strlen(st) > sizeof(text) - 50) if (strlen(text) + strlen(st) > sizeof(text) - 50)
{ {
sprintf(text + strlen(text), "And more...\n"); Q_strlcat(text, "And more...\n", sizeof(text));
gi.cprintf(ent, PRINT_HIGH, "%s", text); gi.cprintf(ent, PRINT_HIGH, "%s", text);
return; return;
} }

View file

@ -156,7 +156,7 @@ Sys_Error(char *error, ...)
char text[1024]; char text[1024];
va_start(argptr, error); va_start(argptr, error);
vsprintf(text, error, argptr); vsnprintf(text, sizeof(text), error, argptr);
va_end(argptr); va_end(argptr);
gi.error(ERR_FATAL, "%s", text); gi.error(ERR_FATAL, "%s", text);
@ -169,7 +169,7 @@ Com_Printf(char *msg, ...)
char text[1024]; char text[1024];
va_start(argptr, msg); va_start(argptr, msg);
vsprintf(text, msg, argptr); vsnprintf(text, sizeof(text), msg, argptr);
va_end(argptr); va_end(argptr);
gi.dprintf("%s", text); gi.dprintf("%s", text);

View file

@ -284,11 +284,11 @@ SVCmd_WriteIP_f(void)
if (!*game->string) if (!*game->string)
{ {
sprintf(name, "%s/listip.cfg", GAMEVERSION); snprintf(name, sizeof(name), "%s/listip.cfg", GAMEVERSION);
} }
else else
{ {
sprintf(name, "%s/listip.cfg", game->string); snprintf(name, sizeof(name), "%s/listip.cfg", game->string);
} }
gi.cprintf(NULL, PRINT_HIGH, "Writing %s.\n", name); gi.cprintf(NULL, PRINT_HIGH, "Writing %s.\n", name);

View file

@ -1637,7 +1637,7 @@ Sys_Error(char *error, ...)
char text[1024]; char text[1024];
va_start(argptr, error); va_start(argptr, error);
vsprintf(text, error, argptr); vsnprintf(text, sizeof(text), error, argptr);
va_end(argptr); va_end(argptr);
ri.Sys_Error(ERR_FATAL, "%s", text); ri.Sys_Error(ERR_FATAL, "%s", text);
@ -1650,7 +1650,7 @@ Com_Printf(char *fmt, ...)
char text[1024]; char text[1024];
va_start(argptr, fmt); va_start(argptr, fmt);
vsprintf(text, fmt, argptr); vsnprintf(text, sizeof(text), fmt, argptr);
va_end(argptr); va_end(argptr);
ri.Con_Printf(PRINT_ALL, "%s", text); ri.Con_Printf(PRINT_ALL, "%s", text);

View file

@ -78,7 +78,7 @@ PF_dprintf(char *fmt, ...)
va_list argptr; va_list argptr;
va_start(argptr, fmt); va_start(argptr, fmt);
vsprintf(msg, fmt, argptr); vsnprintf(msg, sizeof(msg), fmt, argptr);
va_end(argptr); va_end(argptr);
Com_Printf("%s", msg); Com_Printf("%s", msg);
@ -107,7 +107,7 @@ PF_cprintf(edict_t *ent, int level, char *fmt, ...)
} }
va_start(argptr, fmt); va_start(argptr, fmt);
vsprintf(msg, fmt, argptr); vsnprintf(msg, sizeof(msg), fmt, argptr);
va_end(argptr); va_end(argptr);
if (ent) if (ent)
@ -138,7 +138,7 @@ PF_centerprintf(edict_t *ent, char *fmt, ...)
} }
va_start(argptr, fmt); va_start(argptr, fmt);
vsprintf(msg, fmt, argptr); vsnprintf(msg, sizeof(msg), fmt, argptr);
va_end(argptr); va_end(argptr);
MSG_WriteByte(&sv.multicast, svc_centerprint); MSG_WriteByte(&sv.multicast, svc_centerprint);
@ -156,7 +156,7 @@ PF_error(char *fmt, ...)
va_list argptr; va_list argptr;
va_start(argptr, fmt); va_start(argptr, fmt);
vsprintf(msg, fmt, argptr); vsnprintf(msg, sizeof(msg), fmt, argptr);
va_end(argptr); va_end(argptr);
Com_Error(ERR_DROP, "Game Error: %s", msg); Com_Error(ERR_DROP, "Game Error: %s", msg);

View file

@ -212,7 +212,8 @@ SV_SpawnServer(char *server, char *spawnpoint, server_state_t serverstate,
if (Cvar_VariableValue("deathmatch")) if (Cvar_VariableValue("deathmatch"))
{ {
sprintf(sv.configstrings[CS_AIRACCEL], "%g", sv_airaccelerate->value); snprintf(sv.configstrings[CS_AIRACCEL], sizeof(sv.configstrings[CS_AIRACCEL]),
"%g", sv_airaccelerate->value);
pm_airaccelerate = sv_airaccelerate->value; pm_airaccelerate = sv_airaccelerate->value;
} }
else else

View file

@ -58,7 +58,7 @@ SV_ClientPrintf(client_t *cl, int level, char *fmt, ...)
} }
va_start(argptr, fmt); va_start(argptr, fmt);
vsprintf(string, fmt, argptr); vsnprintf(string, sizeof(string), fmt, argptr);
va_end(argptr); va_end(argptr);
MSG_WriteByte(&cl->netchan.message, svc_print); MSG_WriteByte(&cl->netchan.message, svc_print);
@ -78,7 +78,7 @@ SV_BroadcastPrintf(int level, char *fmt, ...)
int i; int i;
va_start(argptr, fmt); va_start(argptr, fmt);
vsprintf(string, fmt, argptr); vsnprintf(string, sizeof(string), fmt, argptr);
va_end(argptr); va_end(argptr);
/* echo to console */ /* echo to console */
@ -130,7 +130,7 @@ SV_BroadcastCommand(char *fmt, ...)
} }
va_start(argptr, fmt); va_start(argptr, fmt);
vsprintf(string, fmt, argptr); vsnprintf(string, sizeof(string), fmt, argptr);
va_end(argptr); va_end(argptr);
MSG_WriteByte(&sv.multicast, svc_stufftext); MSG_WriteByte(&sv.multicast, svc_stufftext);