return -1;
if ((i = COM_CheckParm("-cddev")) != 0 && i < com_argc - 1) {
- strncpy(cd_dev, com_argv[i + 1], sizeof(cd_dev));
+ strlcpy (cd_dev, com_argv[i + 1], sizeof (cd_dev));
cd_dev[sizeof(cd_dev) - 1] = 0;
}
track = -1;
// get the demo name
- strncpy (name, Cmd_Argv(1), sizeof (name) - 1);
- name[sizeof (name) - 1] = '\0';
- FS_DefaultExtension (name, ".dem");
+ strlcpy (name, Cmd_Argv(1), sizeof (name));
+ FS_DefaultExtension (name, ".dem", sizeof (name));
// start the map up
if (c > 2)
NetConn_ClientFrame();
// open the demo file
- strcpy (name, Cmd_Argv(1));
- FS_DefaultExtension (name, ".dem");
+ strlcpy (name, Cmd_Argv(1), sizeof (name));
+ FS_DefaultExtension (name, ".dem", sizeof (name));
Con_Printf ("Playing demo from %s.\n", name);
cls.demofile = FS_Open (name, "rb", false);
continue;
if (ent->render.model)
- strncpy(name, ent->render.model->name, 25);
+ strlcpy (name, ent->render.model->name, 25);
else
strcpy(name, "--no model--");
- name[25] = 0;
for (j = strlen(name);j < 25;j++)
name[j] = ' ';
Con_Printf ("%3i: %s:%04i (%5i %5i %5i) [%3i %3i %3i] %4.2f %5.3f\n", i, name, ent->render.frame, (int) ent->render.origin[0], (int) ent->render.origin[1], (int) ent->render.origin[2], (int) ent->render.angles[0] % 360, (int) ent->render.angles[1] % 360, (int) ent->render.angles[2] % 360, ent->render.scale, ent->render.alpha);
// parse signon message
str = MSG_ReadString ();
- strncpy (cl.levelname, str, sizeof(cl.levelname)-1);
+ strlcpy (cl.levelname, str, sizeof(cl.levelname));
// seperate the printfs so the server message can have a color
if (cl.protocol != PROTOCOL_NEHAHRAMOVIE) // no messages when playing the Nehahra movie
i &= 31;
while(count > 0)
{
- sprintf(temp, "%3i:%s ", cmdlog[i], cmdlogname[i]);
- strcat(description, temp);
+ snprintf (temp, sizeof (temp), "%3i:%s ", cmdlog[i], cmdlogname[i]);
+ strlcat (description, temp, sizeof (description));
count--;
i++;
i &= 31;
i = MSG_ReadByte ();
if (i >= MAX_LIGHTSTYLES)
Host_Error ("svc_lightstyle >= MAX_LIGHTSTYLES");
- strncpy (cl_lightstyle[i].map, MSG_ReadString(), MAX_STYLESTRING - 1);
+ strlcpy (cl_lightstyle[i].map, MSG_ReadString(), sizeof (cl_lightstyle[i].map));
cl_lightstyle[i].map[MAX_STYLESTRING - 1] = 0;
cl_lightstyle[i].length = strlen(cl_lightstyle[i].map);
break;
i = MSG_ReadByte ();
if (i >= cl.maxclients)
Host_Error ("CL_ParseServerMessage: svc_updatename >= cl.maxclients");
- strcpy (cl.scores[i].name, MSG_ReadString ());
+ strlcpy (cl.scores[i].name, MSG_ReadString (), sizeof (cl.scores[i].name));
break;
case svc_updatefrags:
*/
void SCR_CenterPrint (char *str)
{
- strncpy (scr_centerstring, str, sizeof(scr_centerstring)-1);
+ strlcpy (scr_centerstring, str, sizeof (scr_centerstring));
scr_centertime_off = scr_centertime.value;
scr_centertime_start = cl.time;
return;
}
- strcpy(basename, Cmd_Argv(1));
+ strlcpy (basename, Cmd_Argv(1), sizeof (basename));
size = atoi(Cmd_Argv(2));
if (size != 128 && size != 256 && size != 512 && size != 1024)
{
int i, k;
qbyte lmplabel[256], picname[256];
float x, y;
- strcpy(lmplabel,MSG_ReadString());
- strcpy(picname, MSG_ReadString());
+ strlcpy (lmplabel,MSG_ReadString(), sizeof (lmplabel));
+ strlcpy (picname, MSG_ReadString(), sizeof (picname));
if (gamemode == GAME_NEHAHRA) // LordHavoc: nasty old legacy junk
{
x = MSG_ReadByte();
return; // none found to replace
// change existing one
showlmp[k].isactive = true;
- strcpy(showlmp[k].label, lmplabel);
- strcpy(showlmp[k].pic, picname);
+ strlcpy (showlmp[k].label, lmplabel, sizeof (showlmp[k].label));
+ strlcpy (showlmp[k].pic, picname, sizeof (showlmp[k].pic));
showlmp[k].x = x;
showlmp[k].y = y;
}
a->next = cmd_alias;
cmd_alias = a;
}
- strcpy (a->name, s);
+ strlcpy (a->name, s, sizeof (a->name));
// copy the rest of the command line
cmd[0] = 0; // start out with a null string
c = Cmd_Argc();
for (i=2 ; i< c ; i++)
{
- strcat (cmd, Cmd_Argv(i));
+ strlcat (cmd, Cmd_Argv(i), sizeof (cmd));
if (i != c)
- strcat (cmd, " ");
+ strlcat (cmd, " ", sizeof (cmd));
}
- strcat (cmd, "\n");
+ strlcat (cmd, "\n", sizeof (cmd));
a->value = CopyString (cmd);
}
s = string[stringindex];
stringindex = (stringindex + 1) & 7;
va_start (argptr, format);
- vsprintf (s, format,argptr);
+ vsnprintf (s, sizeof (string[0]), format,argptr);
va_end (argptr);
return s;
struct _finddata_t n_file;
long hFile;
stringlist_t *start, *current;
- strcpy(pattern, path);
- strcat(pattern, "\\*");
+ strlcpy (pattern, path, sizeof (pattern));
+ strlcat (pattern, "\\*", sizeof (pattern));
// ask for the directory listing handle
hFile = _findfirst(pattern, &n_file);
if(hFile != -1)
// Create a package structure in memory
pack = Mem_Alloc (pak_mempool, sizeof (pack_t));
pack->ignorecase = true; // PK3 ignores case
- strcpy (pack->filename, packfile);
+ strlcpy (pack->filename, packfile, sizeof (pack->filename));
pack->handle = packhandle;
pack->numfiles = eocd.nbentries;
pack->mempool = Mem_AllocPool (packfile);
pack = Mem_Alloc(pak_mempool, sizeof (pack_t));
pack->ignorecase = false; // PAK is case sensitive
- strcpy (pack->filename, packfile);
+ strlcpy (pack->filename, packfile, sizeof (pack->filename));
pack->handle = packhandle;
pack->numfiles = numpackfiles;
pack->mempool = Mem_AllocPool(packfile);
size_t size;
packfile_t *file = &pack->files[i];
- strcpy (file->name, info[i].name);
+ strlcpy (file->name, info[i].name, sizeof (file->name));
file->offset = LittleLong(info[i].filepos);
size = LittleLong (info[i].filelen);
file->packsize = size;
pack_t *pak;
char pakfile[MAX_OSPATH];
- strcpy (fs_gamedir, dir);
+ strlcpy (fs_gamedir, dir, sizeof (fs_gamedir));
// add the directory to the search path
search = Mem_Alloc(pak_mempool, sizeof(searchpath_t));
- strcpy (search->filename, dir);
+ strlcpy (search->filename, dir, sizeof (search->filename));
search->next = fs_searchpaths;
fs_searchpaths = search;
// Overrides the system supplied base directory (under GAMENAME)
i = COM_CheckParm ("-basedir");
if (i && i < com_argc-1)
- strcpy (fs_basedir, com_argv[i+1]);
+ strlcpy (fs_basedir, com_argv[i+1], sizeof (fs_basedir));
i = strlen (fs_basedir);
if (i > 0 && (fs_basedir[i-1] == '\\' || fs_basedir[i-1] == '/'))
fs_basedir[i-1] = 0;
// start up with GAMENAME by default (id1)
- strcpy(com_modname, GAMENAME);
+ strlcpy (com_modname, GAMENAME, sizeof (com_modname));
FS_AddGameDirectory (va("%s/"GAMENAME, fs_basedir));
if (gamedirname[0])
{
fs_modified = true;
- strcpy(com_modname, gamedirname);
+ strlcpy (com_modname, gamedirname, sizeof (com_modname));
FS_AddGameDirectory (va("%s/%s", fs_basedir, gamedirname));
}
if (i && i < com_argc-1)
{
fs_modified = true;
- strcpy(com_modname, com_argv[i+1]);
+ strlcpy (com_modname, com_argv[i+1], sizeof (com_modname));
FS_AddGameDirectory (va("%s/%s", fs_basedir, com_argv[i+1]));
}
Sys_Error ("Couldn't load packfile: %s", com_argv[i]);
}
else
- strcpy (search->filename, com_argv[i]);
+ strlcpy (search->filename, com_argv[i], sizeof (search->filename));
search->next = fs_searchpaths;
fs_searchpaths = search;
}
FS_DefaultExtension
==================
*/
-void FS_DefaultExtension (char *path, const char *extension)
+void FS_DefaultExtension (char *path, const char *extension, size_t size_path)
{
const char *src;
src--;
}
- strcat (path, extension);
+ strlcat (path, extension, size_path);
}
// ------ Other functions ------ //
void FS_StripExtension (const char *in, char *out);
-void FS_DefaultExtension (char *path, const char *extension);
+void FS_DefaultExtension (char *path, const char *extension, size_t size_path);
qboolean FS_FileExists (const char *filename); // the file can be into a package
qboolean FS_SysFileExists (const char *filename); // only look for files outside of packages
return;
}
- strncpy (name, Cmd_Argv(1), sizeof (name) - 1);
- name[sizeof (name) - 1] = '\0';
- FS_DefaultExtension (name, ".sav");
+ strlcpy (name, Cmd_Argv(1), sizeof (name));
+ FS_DefaultExtension (name, ".sav", sizeof (name));
Con_Printf ("Saving game to %s...\n", name);
f = FS_Open (name, "w", false);
}
strcpy (sv_loadgame, Cmd_Argv(1));
- FS_DefaultExtension (sv_loadgame, ".sav");
+ FS_DefaultExtension (sv_loadgame, ".sav", sizeof (sv_loadgame));
Con_Printf ("Loading game from %s...\n", sv_loadgame);
}
}
if (Cmd_Argc () == 2)
- strncpy(newName, Cmd_Argv(1), sizeof(host_client->name) - 1);
+ strlcpy (newName, Cmd_Argv(1), sizeof (newName));
else
- strncpy(newName, Cmd_Args(), sizeof(host_client->name) - 1);
- newName[sizeof(host_client->name) - 1] = 0;
+ strlcpy (newName, Cmd_Args(), sizeof (newName));
if (cmd_source == src_command)
{
Con_DPrintf ("%i demo(s) in loop\n", c);
for (i=1 ; i<c+1 ; i++)
- strncpy (cls.demos[i-1], Cmd_Argv(i), sizeof(cls.demos[0])-1);
+ strlcpy (cls.demos[i-1], Cmd_Argv(i), sizeof (cls.demos[i-1]));
// LordHavoc: clear the remaining slots
for (;i <= MAX_DEMOS;i++)
str = FS_Getline (f);
sscanf (str, "%i\n", &version);
str = FS_Getline (f);
- strncpy (m_filenames[i], str, sizeof(m_filenames[i])-1);
+ strlcpy (m_filenames[i], str, sizeof (m_filenames[i]));
// change _ back to space
for (j=0 ; j<SAVEGAME_COMMENT_LENGTH ; j++)
for (i = 0;i < count;i++, in++, out++)
{
- strncpy(out->name, in->name, sizeof(out->name) - 1);
+ strlcpy (out->name, in->name, sizeof (out->name));
out->surfaceflags = LittleLong(in->surfaceflags);
out->nativecontents = LittleLong(in->contents);
out->supercontents = Mod_Q3BSP_SuperContentsFromNativeContents(loadmodel, out->nativecontents);
for (i = 0;i < count;i++, in++, out++)
{
- strncpy(out->shadername, in->shadername, sizeof(out->shadername) - 1);
+ strlcpy (out->shadername, in->shadername, sizeof (out->shadername));
n = LittleLong(in->brushindex);
if (n < 0 || n >= loadmodel->brushq3.num_brushes)
Host_Error("Mod_Q3BSP_LoadEffects: invalid brushindex %i (%i brushes)\n", n, loadmodel->brushq3.num_brushes);
do
{
if (words < 10)
- strncpy(word[words++], com_token, MAX_QPATH - 1);
+ strlcpy(word[words++], com_token, sizeof (word[0]));
else
wordsoverflow = true;
}
skinfileitem = Mem_Alloc(tempmempool, sizeof(skinfileitem_t));
skinfileitem->next = skinfile->items;
skinfile->items = skinfileitem;
- strncpy(skinfileitem->name, word[1], sizeof(skinfileitem->name) - 1);
- strncpy(skinfileitem->replacement, word[2], sizeof(skinfileitem->replacement) - 1);
+ strlcpy (skinfileitem->name, word[1], sizeof (skinfileitem->name));
+ strlcpy (skinfileitem->replacement, word[2], sizeof (skinfileitem->replacement));
}
else
Con_Printf("Mod_LoadSkinFiles: parsing error in file \"%s_%i.skin\" on line #%i: wrong number of parameters to command \"%s\", see documentation in DP_GFX_SKINFILES extension in dpextensions.qc\n", loadmodel->name, i, line, word[0]);
// tag name, like "tag_weapon,"
Con_DPrintf("Mod_LoadSkinFiles: parsed tag #%i \"%s\"\n", numtags, word[0]);
memset(tags + numtags, 0, sizeof(tags[numtags]));
- strncpy(tags[numtags].name, word[0], sizeof(tags[numtags].name) - 1);
+ strlcpy (tags[numtags].name, word[0], sizeof (tags[numtags].name));
numtags++;
}
else if (words == 3 && !strcmp(word[1], ","))
skinfileitem = Mem_Alloc(tempmempool, sizeof(skinfileitem_t));
skinfileitem->next = skinfile->items;
skinfile->items = skinfileitem;
- strncpy(skinfileitem->name, word[0], sizeof(skinfileitem->name) - 1);
- strncpy(skinfileitem->replacement, word[2], sizeof(skinfileitem->replacement) - 1);
+ strlcpy (skinfileitem->name, word[0], sizeof (skinfileitem->name));
+ strlcpy (skinfileitem->replacement, word[2], sizeof (skinfileitem->replacement));
}
else
Con_Printf("Mod_LoadSkinFiles: parsing error in file \"%s_%i.skin\" on line #%i: does not look like tag or mesh specification, or replace command, see documentation in DP_GFX_SKINFILES extension in dpextensions.qc\n", loadmodel->name, i, line);
string += 13;
// hostcache only uses text addresses
LHNETADDRESS_ToString(peeraddress, cname, sizeof(cname), true);
- if ((s = SearchInfostring(string, "gamename" )) != NULL) strncpy(game, s, sizeof(game) - 1);else game[0] = 0;
- if ((s = SearchInfostring(string, "modname" )) != NULL) strncpy(mod , s, sizeof(mod ) - 1);else mod[0] = 0;
- if ((s = SearchInfostring(string, "mapname" )) != NULL) strncpy(map , s, sizeof(map ) - 1);else map[0] = 0;
- if ((s = SearchInfostring(string, "hostname" )) != NULL) strncpy(name, s, sizeof(name) - 1);else name[0] = 0;
+ if ((s = SearchInfostring(string, "gamename" )) != NULL) strlcpy(game, s, sizeof (game));else game[0] = 0;
+ if ((s = SearchInfostring(string, "modname" )) != NULL) strlcpy(mod , s, sizeof (mod ));else mod[0] = 0;
+ if ((s = SearchInfostring(string, "mapname" )) != NULL) strlcpy(map , s, sizeof (map ));else map[0] = 0;
+ if ((s = SearchInfostring(string, "hostname" )) != NULL) strlcpy(name, s, sizeof (name));else name[0] = 0;
if ((s = SearchInfostring(string, "protocol" )) != NULL) c = atoi(s);else c = -1;
if ((s = SearchInfostring(string, "clients" )) != NULL) users = atoi(s);else users = 0;
if ((s = SearchInfostring(string, "sv_maxclients")) != NULL) maxusers = atoi(s);else maxusers = 0;
if (developer.integer)
Con_Printf("Datagram_ParseConnectionless: received CCREP_REJECT from %s.\n", addressstring2);
Con_Printf("%s\n", data);
- strncpy(m_return_reason, data, sizeof(m_return_reason) - 1);
+ strlcpy (m_return_reason, data, sizeof (m_return_reason));
break;
#if 0
case CCREP_SERVER_INFO:
c = MSG_ReadByte();
if (c != NET_PROTOCOL_VERSION)
{
- strncpy(hostcache[n].cname, hostcache[n].name, sizeof(hostcache[n].cname) - 1);
- hostcache[n].cname[sizeof(hostcache[n].cname) - 1] = 0;
+ strlcpy (hostcache[n].cname, hostcache[n].name, sizeof (hostcache[n].cname));
strcpy(hostcache[n].name, "*");
- strncat(hostcache[n].name, hostcache[n].cname, sizeof(hostcache[n].name) - 1);
- hostcache[n].name[sizeof(hostcache[n].name) - 1] = 0;
+ strlcat (hostcache[n].name, hostcache[n].cname, sizeof(hostcache[n].name));
}
strcpy(hostcache[n].cname, cname);
}
val = (void *)&pr_globals[ofs];
def = ED_GlobalAtOfs(ofs);
if (!def)
- sprintf (line,"%i(?)", ofs);
+ snprintf (line, sizeof (line), "%i(?)", ofs);
else
{
s = PR_ValueString (def->type, val);
- sprintf (line,"%i(%s)%s", ofs, PR_GetString(def->s_name), s);
+ snprintf (line, sizeof (line), "%i(%s)%s", ofs, PR_GetString(def->s_name), s);
}
i = strlen(line);
for ( ; i<20 ; i++)
- strcat (line," ");
- strcat (line," ");
+ strlcat (line, " ", sizeof (line));
+ strlcat (line, " ", sizeof (line));
return line;
}
def = ED_GlobalAtOfs(ofs);
if (!def)
- sprintf (line,"%i(?)", ofs);
+ snprintf (line, sizeof (line), "%i(?)", ofs);
else
- sprintf (line,"%i(%s)", ofs, PR_GetString(def->s_name));
+ snprintf (line, sizeof (line), "%i(%s)", ofs, PR_GetString(def->s_name));
i = strlen(line);
for ( ; i<20 ; i++)
- strcat (line," ");
- strcat (line," ");
+ strlcat (line, " ", sizeof (line));
+ strlcat (line, " ", sizeof (line));
return line;
}
tempstring2[259] = 0;
name = tempstring2;
}
- strcat(tempstring, name);
+ strlcat (tempstring, name, sizeof (tempstring));
for (l = strlen(name);l < 14;l++)
strcat(tempstring, " ");
strcat(tempstring, " ");
tempstring2[259] = 0;
name = tempstring2;
}
- strcat(tempstring, name);
- strcat(tempstring, "\n");
+ strlcat (tempstring, name, sizeof (tempstring));
+ strlcat (tempstring, "\n", sizeof (tempstring));
if (strlen(tempstring) >= 4096)
{
Con_Printf("%s", tempstring);
switch(d->type & ~DEF_SAVEGLOBAL)
{
case ev_string:
- strcat(tempstring, "string ");
+ strlcat (tempstring, "string ", sizeof (tempstring));
break;
case ev_entity:
- strcat(tempstring, "entity ");
+ strlcat (tempstring, "entity ", sizeof (tempstring));
break;
case ev_function:
- strcat(tempstring, "function ");
+ strlcat (tempstring, "function ", sizeof (tempstring));
break;
case ev_field:
- strcat(tempstring, "field ");
+ strlcat (tempstring, "field ", sizeof (tempstring));
break;
case ev_void:
- strcat(tempstring, "void ");
+ strlcat (tempstring, "void ", sizeof (tempstring));
break;
case ev_float:
- strcat(tempstring, "float ");
+ strlcat (tempstring, "float ", sizeof (tempstring));
break;
case ev_vector:
- strcat(tempstring, "vector ");
+ strlcat (tempstring, "vector ", sizeof (tempstring));
break;
case ev_pointer:
- strcat(tempstring, "pointer ");
+ strlcat (tempstring, "pointer ", sizeof (tempstring));
break;
default:
- sprintf (tempstring2, "bad type %i ", d->type & ~DEF_SAVEGLOBAL);
- strcat(tempstring, tempstring2);
+ snprintf (tempstring2, sizeof (tempstring2), "bad type %i ", d->type & ~DEF_SAVEGLOBAL);
+ strlcat (tempstring, tempstring2, sizeof (tempstring));
break;
}
if (strlen(name) > 256)
tempstring2[259] = 0;
name = tempstring2;
}
- strcat(tempstring, name);
+ strcat (tempstring, name);
for (j = strlen(name);j < 25;j++)
strcat(tempstring, " ");
- sprintf(tempstring2, "%5d", counts[i]);
- strcat(tempstring, tempstring2);
- strcat(tempstring, "\n");
+ snprintf (tempstring2, sizeof (tempstring2), "%5d", counts[i]);
+ strlcat (tempstring, tempstring2, sizeof (tempstring));
+ strlcat (tempstring, "\n", sizeof (tempstring));
if (strlen(tempstring) >= 4096)
{
Con_Printf("%s", tempstring);
if (s == NULL)
s = "";
// point the string back at host_client->name to keep it safe
- strncpy(host_client->name, s, sizeof(host_client->name) - 1);
+ strlcpy (host_client->name, s, sizeof (host_client->name));
sv_player->v->netname = PR_SetString(host_client->name);
}
if ((val = GETEDICTFIELDVALUE(sv_player, eval_clientcolors)) && host_client->colors != val->_float)
ui->item_count++;
}
memset(it, 0, sizeof(ui_item_t));
- strncpy(it->name, itemname, 32);
+ strlcpy (it->name, itemname, sizeof (it->name));
it->flags = 0;
if (picname || string)
{