for (i = 0, ent = cl.entities;i < cl.num_entities;i++, ent++)
{
+ const char* modelname;
+
if (!ent->state_current.active)
continue;
if (ent->render.model)
- strlcpy (name, ent->render.model->name, 25);
+ modelname = ent->render.model->name;
else
- strcpy(name, "--no model--");
+ modelname = "--no model--";
+ strlcpy(name, modelname, 25);
for (j = (int)strlen(name);j < 25;j++)
name[j] = ' ';
Con_Printf("%3i: %s:%4i (%5i %5i %5i) [%3i %3i %3i] %4.2f %5.3f\n", i, name, ent->render.frame, (int) ent->render.matrix.m[0][3], (int) ent->render.matrix.m[1][3], (int) ent->render.matrix.m[2][3], (int) ent->render.angles[0] % 360, (int) ent->render.angles[1] % 360, (int) ent->render.angles[2] % 360, ent->render.scale, ent->render.alpha);
{
char description[32*64], temp[64];
int count;
- strcpy(description, "packet dump: ");
+ strlcpy(description, "packet dump: ", sizeof(description));
i = cmdcount - 32;
if (i < 0)
i = 0;
{
char description[32*64], temp[64];
int count;
- strcpy (description, "packet dump: ");
+ strlcpy (description, "packet dump: ", sizeof(description));
i = cmdcount - 32;
if (i < 0)
i = 0;
t[0] = 0;
if(!strcasecmp(c, "name"))
- strcpy(t, cl.scores[i].name);
+ strlcpy(t, cl.scores[i].name, sizeof(t));
else
if(!strcasecmp(c, "frags"))
sprintf(t, "%i", cl.scores[i].frags);
if(!t[0])
return;
temp = VM_GetTempString();
- strcpy(temp, t);
+ strlcpy(temp, t, VM_STRINGTEMP_LENGTH);
PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(temp);
}
VM_SAFEPARMCOUNT(1, VM_CL_registercmd);
if(!Cmd_Exists(PRVM_G_STRING(OFS_PARM0)))
{
- t = (char *)Z_Malloc(strlen(PRVM_G_STRING(OFS_PARM0))+1);
- strcpy(t, PRVM_G_STRING(OFS_PARM0));
+ size_t alloclen;
+
+ alloclen = strlen(PRVM_G_STRING(OFS_PARM0)) + 1;
+ t = (char *)Z_Malloc(alloclen);
+ memcpy(t, PRVM_G_STRING(OFS_PARM0), alloclen);
Cmd_AddCommand(t, NULL, "console command created by QuakeC");
}
else
PRVM_G_INT(OFS_RETURN) = 0;
if(s)
{
- strcpy(t, s);
+ strlcpy(t, s, VM_STRINGTEMP_LENGTH);
PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(t);
}
}
char cmd[MAX_INPUTLINE];
int i, c;
const char *s;
+ size_t alloclen;
if (Cmd_Argc() == 1)
{
}
strlcat (cmd, "\n", sizeof (cmd));
- a->value = (char *)Z_Malloc (strlen (cmd) + 1);
- strcpy (a->value, cmd);
+ alloclen = strlen (cmd) + 1;
+ a->value = (char *)Z_Malloc (alloclen);
+ memcpy (a->value, cmd, alloclen);
}
/*
Con_Printf("Cmd_TokenizeString: ran out of %i character buffer space for command arguements\n", CMD_TOKENIZELENGTH);
break;
}
- strcpy (cmd_tokenizebuffer + cmd_tokenizebufferpos, com_token);
+ memcpy (cmd_tokenizebuffer + cmd_tokenizebufferpos, com_token, l);
cmd_argv[cmd_argc] = cmd_tokenizebuffer + cmd_tokenizebufferpos;
cmd_tokenizebufferpos += l;
cmd_argc++;
else
{
// just remove the key from the text
- strcpy(buffer + pos, buffer + pos2);
+ strlcpy(buffer + pos, buffer + pos2, bufferlength - pos);
}
}
extern int dpvsnprintf (char *buffer, size_t buffersize, const char *format, va_list args);
// A bunch of functions are forbidden for security reasons (and also to please MSVS 2005, for some of them)
-#define strcat DO_NOT_USE_STRCAT__USE_STRLCAT
+#define strcat DO_NOT_USE_STRCAT__USE_STRLCAT_OR_MEMCPY
#define strncat DO_NOT_USE_STRNCAT__USE_STRLCAT_OR_MEMCPY
-//#define strcpy DO_NOT_USE_STRCPY__USE_STRLCPY
+#define strcpy DO_NOT_USE_STRCPY__USE_STRLCPY_OR_MEMCPY
#define strncpy DO_NOT_USE_STRNCPY__USE_STRLCPY_OR_MEMCPY
//#define sprintf DO_NOT_USE_SPRINTF__USE_DPSNPRINTF
if (!key_consoleactive)
return; // don't draw anything
- text = strcpy(editlinecopy, key_lines[edit_line]);
+ strlcpy(editlinecopy, key_lines[edit_line], sizeof(editlinecopy));
+ text = editlinecopy;
// Advanced Console Editing by Radix radix@planetquake.com
// Added/Modified by EvilTypeGuy eviltypeguy@qeradiant.com
while ((int)strlen(temptext) >= con_linewidth)
{
DrawQ_ColoredString( 0, v, temptext, con_linewidth, con_textsize.value, con_textsize.value, 1.0, 1.0, 1.0, 1.0, 0, &colorindex );
- strcpy(temptext, &temptext[con_linewidth]);
+ strlcpy(temptext, &temptext[con_linewidth], sizeof(temptext));
v += con_textsize.value;
}
if (strlen(temptext) > 0)
const char *data = NULL;
char keyname[64];
char entfilename[MAX_QPATH];
- strcpy(message, "^1**ERROR**^7");
+ strlcpy(message, "^1**ERROR**^7", sizeof(message));
p = 0;
f = FS_Open(t->filenames[i], "rb", true, false);
if(f)
else
p = 0;
strlcpy(entfilename, t->filenames[i], sizeof(entfilename));
- strcpy(entfilename + strlen(entfilename) - 4, ".ent");
+ memcpy(entfilename + strlen(entfilename) - 4, ".ent", 5);
entities = (char *)FS_LoadFile(entfilename, tempmempool, true, NULL);
if (!entities && lumplen >= 10)
{
*(t->filenames[i]+len[i]+5) = 0;
switch(p)
{
- case Q3BSPVERSION: strcpy((char *)buf, "Q3");break;
- case Q2BSPVERSION: strcpy((char *)buf, "Q2");break;
- case BSPVERSION: strcpy((char *)buf, "Q1");break;
- case MCBSPVERSION: strcpy((char *)buf, "MC");break;
- case 30: strcpy((char *)buf, "HL");break;
- default: strcpy((char *)buf, "??");break;
+ case Q3BSPVERSION: strlcpy((char *)buf, "Q3", sizeof(buf));break;
+ case Q2BSPVERSION: strlcpy((char *)buf, "Q2", sizeof(buf));break;
+ case BSPVERSION: strlcpy((char *)buf, "Q1", sizeof(buf));break;
+ case MCBSPVERSION: strlcpy((char *)buf, "MC", sizeof(buf));break;
+ case 30: strlcpy((char *)buf, "HL", sizeof(buf));break;
+ default: strlcpy((char *)buf, "??", sizeof(buf));break;
}
Con_Printf("%16s (%s) %s\n", t->filenames[i]+5, buf, message);
}
if (!(c + v + a)) // No possible matches
{
if(s2[0])
- strcpy(&key_lines[edit_line][key_linepos], s2);
+ strlcpy(&key_lines[edit_line][key_linepos], s2, sizeof(key_lines[edit_line]) - key_linepos);
return;
}
void Cvar_SetQuick_Internal (cvar_t *var, const char *value)
{
qboolean changed;
+ size_t valuelen;
changed = strcmp(var->string, value);
// LordHavoc: don't reallocate when there is no change
return;
// LordHavoc: don't reallocate when the buffer is the same size
- if (!var->string || strlen(var->string) != strlen(value))
+ valuelen = strlen(value);
+ if (!var->string || strlen(var->string) != valuelen)
{
Z_Free (var->string); // free the old value string
- var->string = (char *)Z_Malloc (strlen(value)+1);
+ var->string = (char *)Z_Malloc (valuelen + 1);
}
- strcpy (var->string, value);
+ memcpy (var->string, value, valuelen + 1);
var->value = atof (var->string);
var->integer = (int) var->value;
if ((var->flags & CVAR_NOTIFY) && changed && sv.active)
int hashindex;
cvar_t *current, *next, *cvar;
char *oldstr;
+ size_t alloclen;
if (developer.integer >= 100)
Con_Printf("Cvar_RegisterVariable({\"%s\", \"%s\", %i});\n", variable->name, variable->string, variable->flags);
// copy the value off, because future sets will Z_Free it
oldstr = variable->string;
- variable->string = (char *)Z_Malloc (strlen(variable->string)+1);
- strcpy (variable->string, oldstr);
- variable->defstring = (char *)Z_Malloc (strlen(variable->string)+1);
- strcpy (variable->defstring, oldstr);
+ alloclen = strlen(variable->string) + 1;
+ variable->string = (char *)Z_Malloc (alloclen);
+ memcpy (variable->string, oldstr, alloclen);
+ variable->defstring = (char *)Z_Malloc (alloclen);
+ memcpy (variable->defstring, oldstr, alloclen);
variable->value = atof (variable->string);
variable->integer = (int) variable->value;
{
int hashindex;
cvar_t *current, *next, *cvar;
+ size_t alloclen;
if (developer.integer >= 100)
Con_Printf("Cvar_Get(\"%s\", \"%s\", %i);\n", name, value, flags);
}
// allocate a new cvar, cvar name, and cvar string
+// TODO: factorize the following code with the one at the end of Cvar_RegisterVariable()
// FIXME: these never get Z_Free'd
cvar = (cvar_t *)Z_Malloc(sizeof(cvar_t));
cvar->flags = flags | CVAR_ALLOCATED;
- cvar->name = (char *)Z_Malloc(strlen(name)+1);
- strcpy(cvar->name, name);
- cvar->string = (char *)Z_Malloc(strlen(value)+1);
- strcpy(cvar->string, value);
- cvar->defstring = (char *)Z_Malloc(strlen(value)+1);
- strcpy(cvar->defstring, value);
+ alloclen = strlen(name) + 1;
+ cvar->name = (char *)Z_Malloc(alloclen);
+ memcpy(cvar->name, name, alloclen);
+ alloclen = strlen(value) + 1;
+ cvar->string = (char *)Z_Malloc(alloclen);
+ memcpy(cvar->string, value, alloclen);
+ cvar->defstring = (char *)Z_Malloc(alloclen);
+ memcpy(cvar->defstring, value, alloclen);
cvar->value = atof (cvar->string);
cvar->integer = (int) cvar->value;
cvar->description = "custom cvar";
{
if (!(var->flags & CVAR_DEFAULTSET))
{
+ size_t alloclen;
+
//Con_Printf("locking cvar %s (%s -> %s)\n", var->name, var->string, var->defstring);
var->flags |= CVAR_DEFAULTSET;
Z_Free(var->defstring);
- var->defstring = (char *)Z_Malloc(strlen(var->string) + 1);
- strcpy(var->defstring, var->string);
+ alloclen = strlen(var->string) + 1;
+ var->defstring = (char *)Z_Malloc(alloclen);
+ memcpy(var->defstring, var->string, alloclen);
}
}
}
// opening and closing streams
-static void StripExtension(char *in, char *out)
-{
- char *dot, *c;
- dot = NULL;
- for (c = in;*c;c++)
- {
- if (*c == ':' || *c == '\\' || *c == '/')
- dot = NULL;
- if (*c == '.')
- dot = c;
- }
- if (dot == NULL)
- {
- // nothing to remove
- strcpy(out, in);
- return;
- }
- else
- {
- memcpy(out, in, dot - in);
- out[dot - in] = 0;
- }
-}
-
// opens a stream
void *dpvsimpledecode_open(char *filename, char **errorstring)
{
{
sfx_t* sfx;
- StripExtension(filename, wavename);
+ FS_StripExtension(filename, wavename, namelen);
strlcat(wavename, ".wav", namelen);
sfx = S_PrecacheSound (wavename, false, false);
if (sfx != NULL)
stringlist_t *stringlistappend(stringlist_t *current, char *text)
{
stringlist_t *newitem;
- newitem = (stringlist_t *)Z_Malloc(strlen(text) + 1 + sizeof(stringlist_t));
+ size_t textlen;
+
+ textlen = strlen(text) + 1;
+ newitem = (stringlist_t *)Z_Malloc(textlen + sizeof(stringlist_t));
newitem->next = NULL;
newitem->text = (char *)(newitem + 1);
- strcpy(newitem->text, text);
+ memcpy(newitem->text, text, textlen);
if (current)
current->next = newitem;
return newitem;
fs_mempool = Mem_AllocPool("file management", 0, NULL);
- strcpy(fs_gamedir, "");
+ strlcpy(fs_gamedir, "", sizeof(fs_gamedir));
// If the base directory is explicitly defined by the compilation process
#ifdef DP_FS_BASEDIR
- strcpy(fs_basedir, DP_FS_BASEDIR);
+ strlcpy(fs_basedir, DP_FS_BASEDIR, sizeof(fs_basedir));
#else
- strcpy(fs_basedir, "");
+ strlcpy(fs_basedir, "", sizeof(fs_basedir));
#ifdef MACOSX
// FIXME: is there a better way to find the directory outside the .app?
void FS_StripExtension (const char *in, char *out, size_t size_out)
{
char *last = NULL;
+ char currentchar;
if (size_out == 0)
return;
- while (*in && size_out > 1)
+ while ((currentchar = *in) && size_out > 1)
{
- if (*in == '.')
+ if (currentchar == '.')
last = out;
- else if (*in == '/' || *in == '\\' || *in == ':')
+ else if (currentchar == '/' || currentchar == '\\' || currentchar == ':')
last = NULL;
- *out++ = *in++;
+ *out++ = currentchar;
+ in++;
size_out--;
}
if (last)
pak = searchpath->pack;
for (i = 0;i < pak->numfiles;i++)
{
- strcpy(temp, pak->files[i].name);
+ strlcpy(temp, pak->files[i].name, sizeof(temp));
while (temp[0])
{
if (matchpattern(temp, (char *)pattern, true))
numchars = 0;
for (listtemp = liststart;listtemp;listtemp = listtemp->next)
{
+ size_t textlen;
search->filenames[numfiles] = search->filenamesbuffer + numchars;
- strcpy(search->filenames[numfiles], listtemp->text);
+ textlen = strlen(listtemp->text) + 1;
+ memcpy(search->filenames[numfiles], listtemp->text, textlen);
numfiles++;
- numchars += (int)strlen(listtemp->text) + 1;
+ numchars += (int)textlen;
}
if (liststart)
stringlistfree(liststart);
return cachepics; // return the first one
}
pic = cachepics + (numcachepics++);
- strcpy (pic->name, picname);
+ strlcpy (pic->name, picname, sizeof(pic->name));
// link into list
pic->chain = cachepichash[hashkey];
cachepichash[hashkey] = pic;
l = (int)strlen(entname) - 4;
if (l >= 0 && !strcmp(entname + l, ".bsp"))
{
- strcpy(entname + l, ".ent");
+ memcpy(entname + l, ".ent", 5);
if ((entities = (char *)FS_LoadFile(entname, tempmempool, true, NULL)))
{
CL_ParseEntityLump(entities);
Sys_Error ("Host_Error: recursively entered (original error was: %s new error is: %s)", hosterrorstring2, hosterrorstring1);
hosterror = true;
- strcpy(hosterrorstring2, hosterrorstring1);
+ strlcpy(hosterrorstring2, hosterrorstring1, sizeof(hosterrorstring2));
CL_Parse_DumpPacket();
svs.serverflags = 0; // haven't completed an episode yet
allowcheats = sv_cheats.integer != 0;
- strcpy(level, Cmd_Argv(1));
+ strlcpy(level, Cmd_Argv(1), sizeof(level));
SV_SpawnServer(level);
if (sv.active && cls.state == ca_disconnected)
CL_EstablishConnection("local:1");
SV_SaveSpawnparms ();
SV_VM_End();
allowcheats = sv_cheats.integer != 0;
- strcpy(level, Cmd_Argv(1));
+ strlcpy(level, Cmd_Argv(1), sizeof(level));
SV_SpawnServer(level);
if (sv.active && cls.state == ca_disconnected)
CL_EstablishConnection("local:1");
key_dest = key_game;
allowcheats = sv_cheats.integer != 0;
- strcpy(mapname, sv.name);
+ strlcpy(mapname, sv.name, sizeof(mapname));
SV_SpawnServer(mapname);
if (sv.active && cls.state == ca_disconnected)
CL_EstablishConnection("local:1");
return;
}
- strcpy (filename, Cmd_Argv(1));
+ strlcpy (filename, Cmd_Argv(1), sizeof(filename));
FS_DefaultExtension (filename, ".sav", sizeof (filename));
Con_Printf("Loading game from %s...\n", filename);
// mapname
COM_ParseTokenConsole(&t);
- strcpy (mapname, com_token);
+ strlcpy (mapname, com_token, sizeof(mapname));
// time
COM_ParseTokenConsole(&t);
{
if (host_client->spawned)
SV_BroadcastPrintf("%s changed name to %s\n", host_client->old_name, host_client->name);
- strcpy(host_client->old_name, host_client->name);
+ strlcpy(host_client->old_name, host_client->name, sizeof(host_client->old_name));
// send notification to all clients
MSG_WriteByte (&sv.reliable_datagram, svc_updatename);
MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_playermodel)->string = PRVM_SetEngineString(host_client->playermodel);
if (strcmp(host_client->old_model, host_client->playermodel))
{
- strcpy(host_client->old_model, host_client->playermodel);
+ strlcpy(host_client->old_model, host_client->playermodel, sizeof(host_client->old_model));
/*// send notification to all clients
MSG_WriteByte (&sv.reliable_datagram, svc_updatepmodel);
MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
{
//if (host_client->spawned)
// SV_BroadcastPrintf("%s changed skin to %s\n", host_client->name, host_client->playerskin);
- strcpy(host_client->old_skin, host_client->playerskin);
+ strlcpy(host_client->old_skin, host_client->playerskin, sizeof(host_client->old_skin));
/*// send notification to all clients
MSG_WriteByte (&sv.reliable_datagram, svc_updatepskin);
MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
}
-void Image_StripImageExtension (const char *in, char *out)
+static void Image_StripImageExtension (const char *in, char *out, size_t size_out)
{
const char *end, *temp;
+
+ if (size_out == 0)
+ return;
+
end = in + strlen(in);
if ((end - in) >= 4)
{
|| strcmp(temp, ".png") == 0
|| strcmp(temp, ".jpg") == 0)
end = temp;
- while (in < end)
+ while (in < end && size_out > 1)
+ {
*out++ = *in++;
+ size_out--;
+ }
*out++ = 0;
}
else
- strcpy(out, in);
+ strlcpy(out, in, size_out);
}
typedef struct imageformat_s
Mem_CheckSentinelsGlobal();
if (developer_texturelogging.integer)
Log_Printf("textures.log", "%s\n", filename);
- strlcpy(basename, filename, sizeof(basename));
- Image_StripImageExtension(basename, basename); // strip filename extensions to allow replacement by other types
+ Image_StripImageExtension(filename, basename, sizeof(basename)); // strip filename extensions to allow replacement by other types
// replace *'s with #, so commandline utils don't get confused when dealing with the external files
for (c = basename;*c;c++)
if (*c == '*')
unsigned char *bumppixels;
int bumppixels_width, bumppixels_height;
char name[MAX_QPATH];
- strlcpy(name, shadername, sizeof(name));
- Image_StripImageExtension(name, name);
+ Image_StripImageExtension(shadername, name, sizeof(name));
memset(s, 0, sizeof(*s));
s->basepixels = loadimagepixels(name, false, 0, 0);
if (s->basepixels == NULL)
{
if (key_linepos > 1)
{
- strcpy(key_lines[edit_line] + key_linepos - 1, key_lines[edit_line] + key_linepos);
+ strlcpy(key_lines[edit_line] + key_linepos - 1, key_lines[edit_line] + key_linepos, sizeof(key_lines[edit_line]) + 1 - key_linepos);
key_linepos--;
}
return;
// delete char on cursor
if (key == K_DEL || key == K_KP_DEL)
{
- if (key_linepos < (int)strlen(key_lines[edit_line]))
- strcpy(key_lines[edit_line] + key_linepos, key_lines[edit_line] + key_linepos + 1);
+ size_t linelen;
+ linelen = strlen(key_lines[edit_line]);
+ if (key_linepos < (int)linelen)
+ memmove(key_lines[edit_line] + key_linepos, key_lines[edit_line] + key_linepos + 1, linelen - key_linepos);
return;
}
{
if (history_line > 0 && key_lines[history_line-1][1])
{
+ size_t linelen;
history_line--;
- strcpy(key_lines[edit_line], key_lines[history_line]);
- key_linepos = (int)strlen(key_lines[edit_line]);
+ linelen = strlen(key_lines[edit_line]);
+ memcpy(key_lines[edit_line], key_lines[history_line], linelen + 1);
+ key_linepos = (int)linelen;
}
return;
}
}
else
{
- strcpy(key_lines[edit_line], key_lines[history_line]);
- key_linepos = (int)strlen(key_lines[edit_line]);
+ size_t linelen;
+ linelen = strlen(key_lines[edit_line]);
+ memcpy(key_lines[edit_line], key_lines[history_line], linelen + 1);
+ key_linepos = (int)linelen;
}
return;
}
// allocate memory for new binding
l = strlen (binding);
newbinding = (char *)Z_Malloc (l + 1);
- strcpy (newbinding, binding);
+ memcpy (newbinding, binding, l + 1);
newbinding[l] = 0;
keybindings[bindmap][keynum] = newbinding;
}
{
if (stringbuffersize >= 6)
{
- strcpy(string, "local");
+ memcpy(string, "local", 6);
return 1;
}
}
for (i=0 ; i<MAX_SAVEGAMES ; i++)
{
- strcpy (m_filenames[i], "--- UNUSED SLOT ---");
+ strlcpy (m_filenames[i], "--- UNUSED SLOT ---", sizeof(m_filenames[i]));
loadable[i] = false;
sprintf (name, "s%i.sav", (int)i);
f = FS_Open (name, "rb", false, false);
key_dest = key_menu;
m_state = m_setup;
m_entersound = true;
- strcpy(setup_myname, cl_name.string);
+ strlcpy(setup_myname, cl_name.string, sizeof(setup_myname));
setup_top = setup_oldtop = cl_color.integer >> 4;
setup_bottom = setup_oldbottom = cl_color.integer & 15;
setup_rate = cl_rate.integer;
// LordHavoc: redesigned to print more than 2 keys, inspired by Tomaz's MiniRacer
if (keys[0] == -1)
- strcpy(keystring, "???");
+ strlcpy(keystring, "???", sizeof(keystring));
else
{
keystring[0] = 0;
// get scene name from first frame
pinframe = (daliasframe_t *)datapointer;
- strcpy(scene->name, pinframe->name);
+ strlcpy(scene->name, pinframe->name, sizeof(scene->name));
scene->firstframe = pose;
scene->framecount = groupframes;
scene->framerate = 1.0f / interval;
// store the info about the new skin
Mod_BuildAliasSkinFromSkinFrame(loadmodel->data_textures + totalskins * loadmodel->num_surfaces, &tempskinframe);
- strcpy(loadmodel->skinscenes[loadmodel->numskins].name, name);
+ strlcpy(loadmodel->skinscenes[loadmodel->numskins].name, name, sizeof(loadmodel->skinscenes[loadmodel->numskins].name));
loadmodel->skinscenes[loadmodel->numskins].firstframe = totalskins;
loadmodel->skinscenes[loadmodel->numskins].framecount = 1;
loadmodel->skinscenes[loadmodel->numskins].framerate = 10.0f;
out[k] = v[vertremap[k]];
datapointer += numxyz * sizeof(trivertx_t);
- strcpy(loadmodel->animscenes[i].name, pinframe->name);
+ strlcpy(loadmodel->animscenes[i].name, pinframe->name, sizeof(loadmodel->animscenes[i].name));
loadmodel->animscenes[i].firstframe = i;
loadmodel->animscenes[i].framecount = 1;
loadmodel->animscenes[i].framerate = 10;
loadmodel->animscenes = (animscene_t *)Mem_Alloc(loadmodel->mempool, loadmodel->numframes * sizeof(animscene_t));
for (i = 0, pinframe = (md3frameinfo_t *)((unsigned char *)pinmodel + LittleLong(pinmodel->lump_frameinfo));i < loadmodel->numframes;i++, pinframe++)
{
- strcpy(loadmodel->animscenes[i].name, pinframe->name);
+ strlcpy(loadmodel->animscenes[i].name, pinframe->name, sizeof(loadmodel->animscenes[i].name));
loadmodel->animscenes[i].firstframe = i;
loadmodel->animscenes[i].framecount = 1;
loadmodel->animscenes[i].framerate = 10;
loadmodel->data_tags = (aliastag_t *)Mem_Alloc(loadmodel->mempool, loadmodel->num_tagframes * loadmodel->num_tags * sizeof(aliastag_t));
for (i = 0, pintag = (md3tag_t *)((unsigned char *)pinmodel + LittleLong(pinmodel->lump_tags));i < loadmodel->num_tagframes * loadmodel->num_tags;i++, pintag++)
{
- strcpy(loadmodel->data_tags[i].name, pintag->name);
+ strlcpy(loadmodel->data_tags[i].name, pintag->name, sizeof(loadmodel->data_tags[i].name));
loadmodel->data_tags[i].matrix = identitymatrix;
for (j = 0;j < 3;j++)
{
// fill out all slots with notexture
for (i = 0, tx = loadmodel->data_textures;i < loadmodel->num_textures;i++, tx++)
{
- strcpy(tx->name, "NO TEXTURE FOUND");
+ strlcpy(tx->name, "NO TEXTURE FOUND", sizeof(tx->name));
tx->width = 16;
tx->height = 16;
tx->skin.base = r_texture_notexture;
name[j] += 'a' - 'A';
tx = loadmodel->data_textures + i;
- strcpy(tx->name, name);
+ strlcpy(tx->name, name, sizeof(tx->name));
tx->width = mtwidth;
tx->height = mtheight;
if (com_token[0] == '}')
break; // end of worldspawn
if (com_token[0] == '_')
- strcpy(key, com_token + 1);
+ strlcpy(key, com_token + 1, sizeof(key));
else
- strcpy(key, com_token);
+ strlcpy(key, com_token, sizeof(key));
while (key[strlen(key)-1] == ' ') // remove trailing spaces
key[strlen(key)-1] = 0;
if (!COM_ParseTokenConsole(&data))
{
k = value[i];
value[i] = 0;
- strcpy(wadname, "textures/");
+ strlcpy(wadname, "textures/", sizeof(wadname));
strlcat(wadname, &value[j], sizeof(wadname));
W_LoadTextureWadFile(wadname, false);
j = i+1;
// copy the base model to this one
*mod = *loadmodel;
// rename the clone back to its proper name
- strcpy(mod->name, name);
+ strlcpy(mod->name, name, sizeof(mod->name));
// textures and memory belong to the main model
mod->texturepool = NULL;
mod->mempool = NULL;
if (com_token[0] == '}')
break; // end of worldspawn
if (com_token[0] == '_')
- strcpy(key, com_token + 1);
+ strlcpy(key, com_token + 1, sizeof(key));
else
- strcpy(key, com_token);
+ strlcpy(key, com_token, sizeof(key));
while (key[strlen(key)-1] == ' ') // remove trailing spaces
key[strlen(key)-1] = 0;
if (!COM_ParseTokenConsole(&data))
break; // error
- strcpy(value, com_token);
+ strlcpy(value, com_token, sizeof(value));
if (!strcmp("gridsize", key))
{
if (sscanf(value, "%f %f %f", &v[0], &v[1], &v[2]) == 3 && v[0] != 0 && v[1] != 0 && v[2] != 0)
sprintf(name, "*%i", i);
mod = Mod_FindName(name);
*mod = *loadmodel;
- strcpy(mod->name, name);
+ strlcpy(mod->name, name, sizeof(mod->name));
// textures and memory belong to the main model
mod->texturepool = NULL;
mod->mempool = NULL;
char name[MAX_QPATH];
qboolean isworldmodel;
qboolean used;
- strcpy(name, mod->name);
+ strlcpy(name, mod->name, sizeof(name));
isworldmodel = mod->isworldmodel;
used = mod->used;
// free textures/memory attached to the model
// clear the struct to make it available
memset(mod, 0, sizeof(model_t));
// restore the fields we want to preserve
- strcpy(mod->name, name);
+ strlcpy(mod->name, name, sizeof(mod->name));
mod->isworldmodel = isworldmodel;
mod->used = used;
mod->loaded = false;
if (mod_numknown == i)
mod_numknown++;
mod = mod_known + i;
- strcpy (mod->name, name);
+ strlcpy (mod->name, name, sizeof(mod->name));
mod->loaded = false;
mod->used = true;
return mod;
cvar_string = Cvar_VariableString(name);
- strcpy(out, cvar_string);
+ strlcpy(out, cvar_string, VM_STRINGTEMP_LENGTH);
PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(out);
}
cvar_string = Cvar_VariableDefString(name);
- strcpy(out, cvar_string);
+ strlcpy(out, cvar_string, VM_STRINGTEMP_LENGTH);
PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(out);
}
{
char *out;
char string[VM_STRINGTEMP_LENGTH];
+ size_t alloclen;
VM_SAFEPARMCOUNT(1,VM_strzone);
VM_VarString(0, string, sizeof(string));
- PRVM_G_INT(OFS_RETURN) = PRVM_AllocString(strlen(string) + 1, &out);
- strcpy(out, string);
+ alloclen = strlen(string) + 1;
+ PRVM_G_INT(OFS_RETURN) = PRVM_AllocString(alloclen, &out);
+ memcpy(out, string, alloclen);
}
/*
pos = 0;
while(COM_ParseToken(&p, false))
{
+ size_t tokenlen;
if (num_tokens >= (int)(sizeof(tokens)/sizeof(tokens[0])))
break;
- if (pos + strlen(com_token) + 1 > sizeof(tokenbuf))
+ tokenlen = strlen(com_token) + 1;
+ if (pos + tokenlen > sizeof(tokenbuf))
break;
tokens[num_tokens++] = tokenbuf + pos;
- strcpy(tokenbuf + pos, com_token);
- pos += strlen(com_token) + 1;
+ memcpy(tokenbuf + pos, com_token, tokenlen);
+ pos += tokenlen;
}
PRVM_G_FLOAT(OFS_RETURN) = num_tokens;
}
tmp = VM_GetTempString();
- strcpy(tmp, VM_SEARCHLIST[handle]->filenames[filenum]);
+ strlcpy(tmp, VM_SEARCHLIST[handle]->filenames[filenum], VM_STRINGTEMP_LENGTH);
PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(tmp);
}
tmp = VM_GetTempString();
- strcpy(tmp, Key_KeynumToString(keynum));
+ strlcpy(tmp, Key_KeynumToString(keynum), VM_STRINGTEMP_LENGTH);
PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(tmp);
}
return;
}
- strcpy( out, in );
+ strlcpy(out, in, VM_STRINGTEMP_LENGTH);
PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( outstr );
}
for( ; *set ; *out++ = *set++ );
*out++ = '\'';
- strcpy( out, in );
+ strlcpy(out, in, VM_STRINGTEMP_LENGTH);
PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( outstr );
}
for(i=0;i<b1->num_strings;i++)
if(b1->strings[i] && b1->strings[i][0])
{
- b2->strings[i] = (char *)Z_Malloc(strlen(b1->strings[i])+1);
+ size_t stringlen;
+ stringlen = strlen(b1->strings[i]) + 1;
+ b2->strings[i] = (char *)Z_Malloc(stringlen);
if(!b2->strings[i])
{
VM_Warning("VM_buf_copy: not enough memory for buffer %i used in %s\n", (int)PRVM_G_FLOAT(OFS_PARM1), PRVM_NAME);
break;
}
- strcpy(b2->strings[i], b1->strings[i]);
+ memcpy(b2->strings[i], b1->strings[i], stringlen);
}
}
int bufindex, strindex;
qcstrbuffer_t *b;
const char *news;
+ size_t alloclen;
VM_SAFEPARMCOUNT(3, VM_bufstr_set);
}
if(b->strings[strindex])
Z_Free(b->strings[strindex]);
- b->strings[strindex] = (char *)Z_Malloc(strlen(news)+1);
- strcpy(b->strings[strindex], news);
+ alloclen = strlen(news) + 1;
+ b->strings[strindex] = (char *)Z_Malloc(alloclen);
+ memcpy(b->strings[strindex], news, alloclen);
}
/*
int bufindex, order, strindex;
qcstrbuffer_t *b;
const char *string;
+ size_t alloclen;
VM_SAFEPARMCOUNT(3, VM_bufstr_add);
}
if(b->strings[strindex])
Z_Free(b->strings[strindex]);
- b->strings[strindex] = (char *)Z_Malloc(strlen(string)+1);
- strcpy(b->strings[strindex], string);
+ alloclen = strlen(string) + 1;
+ b->strings[strindex] = (char *)Z_Malloc(alloclen);
+ memcpy(b->strings[strindex], string, alloclen);
PRVM_G_FLOAT(OFS_RETURN) = strindex;
}
if (com_token[0] == '}')
break;
- strcpy (keyname, com_token);
+ strlcpy (keyname, com_token, sizeof(keyname));
// parse value
if (!COM_ParseTokenConsole(&data))
// and allow them to be turned into vectors. (FIXME...)
if (!strcmp(com_token, "angle"))
{
- strcpy (com_token, "angles");
+ strlcpy (com_token, "angles", sizeof(com_token));
anglehack = true;
}
else
// FIXME: change light to _light to get rid of this hack
if (!strcmp(com_token, "light"))
- strcpy (com_token, "light_lev"); // hack for single light def
+ strlcpy (com_token, "light_lev", sizeof(com_token)); // hack for single light def
- strcpy (keyname, com_token);
+ strlcpy (keyname, com_token, sizeof(keyname));
// another hack to fix keynames with trailing spaces
n = strlen(keyname);
if (anglehack)
{
char temp[32];
- strcpy (temp, com_token);
+ strlcpy (temp, com_token, sizeof(temp));
sprintf (com_token, "0 %s 0", temp);
}
rtlight->cullmaxs[2] = rtlight->shadoworigin[2] + rtlight->radius;
rtlight->cubemapname[0] = 0;
if (light->cubemapname[0])
- strcpy(rtlight->cubemapname, light->cubemapname);
+ strlcpy(rtlight->cubemapname, light->cubemapname, sizeof(rtlight->cubemapname));
else if (light->cubemapnum > 0)
sprintf(rtlight->cubemapname, "cubemaps/%i", light->cubemapnum);
rtlight->shadow = light->shadow;
if (i >= MAX_CUBEMAPS)
return r_texture_whitecube;
numcubemaps++;
- strcpy(cubemaps[i].basename, basename);
+ strlcpy(cubemaps[i].basename, basename, sizeof(cubemaps[i].basename));
cubemaps[i].texture = R_Shadow_LoadCubemap(cubemaps[i].basename);
if (!cubemaps[i].texture)
cubemaps[i].texture = r_texture_whitecube;
// remove quotes on cubemapname
if (cubemapname[0] == '"' && cubemapname[strlen(cubemapname) - 1] == '"')
{
- cubemapname[strlen(cubemapname)-1] = 0;
- strcpy(cubemapname, cubemapname + 1);
+ size_t namelen;
+ namelen = strlen(cubemapname) - 2;
+ memmove(cubemapname, cubemapname + 1, namelen);
+ cubemapname[namelen] = '\0';
}
if (a < 8)
{
if (com_token[0] == '}')
break; // end of entity
if (com_token[0] == '_')
- strcpy(key, com_token + 1);
+ strlcpy(key, com_token + 1, sizeof(key));
else
- strcpy(key, com_token);
+ strlcpy(key, com_token, sizeof(key));
while (key[strlen(key)-1] == ' ') // remove trailing spaces
key[strlen(key)-1] = 0;
if (!COM_ParseTokenConsole(&data))
break; // error
- strcpy(value, com_token);
+ strlcpy(value, com_token, sizeof(value));
// now that we have the key pair worked out...
if (!strcmp("light", key))
return;
}
if (Cmd_Argc() == 3)
- strcpy(cubemapname, Cmd_Argv(2));
+ strlcpy(cubemapname, Cmd_Argv(2), sizeof(cubemapname));
else
cubemapname[0] = 0;
}
r_shadow_bufferlight.radius = r_shadow_selectedlight->radius;
r_shadow_bufferlight.style = r_shadow_selectedlight->style;
if (r_shadow_selectedlight->cubemapname)
- strcpy(r_shadow_bufferlight.cubemapname, r_shadow_selectedlight->cubemapname);
+ strlcpy(r_shadow_bufferlight.cubemapname, r_shadow_selectedlight->cubemapname, sizeof(r_shadow_bufferlight.cubemapname));
else
r_shadow_bufferlight.cubemapname[0] = 0;
r_shadow_bufferlight.shadow = r_shadow_selectedlight->shadow;
return false;
}
- strcpy(skyname, sky);
+ strlcpy(skyname, sky, sizeof(skyname));
return R_LoadSkyBox();
}
{
if (color != (cl.scores[fragsort[i]].colors & 15))
{
+ const char* teamname;
+
color = cl.scores[fragsort[i]].colors & 15;
teamlines++;
- if (color == 4)
- strcpy(teams[teamlines-1].name, "^1Red Team");
- else if (color == 13)
- strcpy(teams[teamlines-1].name, "^4Blue Team");
- else if (color == 9)
- strcpy(teams[teamlines-1].name, "^6Pink Team");
- else if (color == 12)
- strcpy(teams[teamlines-1].name, "^3Yellow Team");
- else
- strcpy(teams[teamlines-1].name, "Total Team Score");
+ switch (color)
+ {
+ case 4:
+ teamname = "^1Red Team";
+ break;
+ case 13:
+ teamname = "^4Blue Team";
+ break;
+ case 9:
+ teamname = "^6Pink Team";
+ break;
+ case 12:
+ teamname = "^3Yellow Team";
+ break;
+ default:
+ teamname = "Total Team Score";
+ break;
+ }
+ strlcpy(teams[teamlines-1].name, teamname, sizeof(teams[teamlines-1].name));
teams[teamlines-1].frags = 0;
teams[teamlines-1].colors = color + 16 * color;
if (S_LoadWavFile (namebuffer, sfx))
return true;
if (len >= 4 && !strcasecmp (namebuffer + len - 4, ".wav"))
- strcpy (namebuffer + len - 3, "ogg");
+ memcpy (namebuffer + len - 3, "ogg", 4);
if (OGG_LoadVorbisFile (namebuffer, sfx))
return true;
}
if (S_LoadWavFile (namebuffer, sfx))
return true;
if (len >= 4 && !strcasecmp (namebuffer + len - 4, ".wav"))
- strcpy (namebuffer + len - 3, "ogg");
+ memcpy (namebuffer + len - 3, "ogg", 4);
if (OGG_LoadVorbisFile (namebuffer, sfx))
return true;
Con_DPrintf("Client %s connected\n", client->netconnection ? client->netconnection->address : "botclient");
- strcpy(client->name, "unconnected");
- strcpy(client->old_name, "unconnected");
+ strlcpy(client->name, "unconnected", sizeof(client->name));
+ strlcpy(client->old_name, "unconnected", sizeof(client->old_name));
client->spawned = false;
client->edict = PRVM_EDICT_NUM(clientnum+1);
if (client->netconnection)
{
if (host_client->spawned)
SV_BroadcastPrintf("%s changed name to %s\n", host_client->old_name, host_client->name);
- strcpy(host_client->old_name, host_client->name);
+ strlcpy(host_client->old_name, host_client->name, sizeof(host_client->old_name));
// send notification to all clients
MSG_WriteByte (&sv.reliable_datagram, svc_updatename);
MSG_WriteByte (&sv.reliable_datagram, i);
worldmodel->used = true;
strlcpy (sv.name, server, sizeof (sv.name));
- strcpy(sv.modelname, modelname);
+ strlcpy(sv.modelname, modelname, sizeof(sv.modelname));
sv.worldmodel = worldmodel;
sv.models[1] = sv.worldmodel;
{
if ((cliptext = GlobalLock (hClipboardData)) != 0)
{
- data = Z_Malloc (GlobalSize(hClipboardData)+1);
- strcpy (data, cliptext);
+ size_t allocsize;
+ allocsize = GlobalSize (hClipboardData) + 1;
+ data = Z_Malloc (allocsize);
+ strlcpy (data, cliptext, allocsize);
GlobalUnlock (hClipboardData);
}
}
{
if ((cliptext = GlobalLock (hClipboardData)) != 0)
{
- data = Z_Malloc (GlobalSize(hClipboardData)+1);
- strcpy (data, cliptext);
+ size_t allocsize;
+ allocsize = GlobalSize (hClipboardData) + 1;
+ data = Z_Malloc (allocsize);
+ strlcpy (data, cliptext, allocsize);
GlobalUnlock (hClipboardData);
}
}
Con_Printf("Unable to open symbol list for %s\n", name);
return false;
}
- strcpy(gl_driver, name);
+ strlcpy(gl_driver, name, sizeof(gl_driver));
return true;
}
Con_Printf("Unable to open symbol list for %s\n", name);
return false;
}
- strcpy(gl_driver, name);
+ strlcpy(gl_driver, name, sizeof(gl_driver));
return true;
}
Con_Printf("Unable to LoadLibrary %s\n", name);
return false;
}
- strcpy(gl_driver, name);
+ strlcpy(gl_driver, name, sizeof(gl_driver));
return true;
}