if (!cl.worldmodel)
return;
- FS_StripExtension(cl.worldmodel->name, name);
- strcat(name, ".pts");
+ FS_StripExtension (cl.worldmodel->name, name, sizeof (name));
+ strlcat (name, ".pts", sizeof (name));
#if WORKINGLQUAKE
pointfile = COM_LoadTempFile (name);
#else
void COM_InitGameType (void)
{
char name[MAX_OSPATH];
- FS_StripExtension(com_argv[0], name);
- COM_ToLowerString(name, name);
+ FS_StripExtension (com_argv[0], name, sizeof (name));
+ COM_ToLowerString (name, name, sizeof (name));
if (strstr(name, "transfusion"))
gamemode = GAME_TRANSFUSION;
//======================================
-// LordHavoc: added these because they are useful
-void COM_ToLowerString(const char *in, char *out)
+void COM_ToLowerString (const char *in, char *out, size_t size_out)
{
- while (*in)
+ if (size_out == 0)
+ return;
+
+ while (*in && size_out > 1)
{
if (*in >= 'A' && *in <= 'Z')
*out++ = *in++ + 'a' - 'A';
else
*out++ = *in++;
+ size_out--;
}
+ *out = '\0';
}
-void COM_ToUpperString(const char *in, char *out)
+void COM_ToUpperString (const char *in, char *out, size_t size_out)
{
- while (*in)
+ if (size_out == 0)
+ return;
+
+ while (*in && size_out > 1)
{
if (*in >= 'a' && *in <= 'z')
*out++ = *in++ + 'A' - 'a';
else
*out++ = *in++;
+ size_out--;
}
+ *out = '\0';
}
int COM_StringBeginsWith(const char *s, const char *match)
extern char *gamedirname;
extern char com_modname[MAX_OSPATH];
-// LordHavoc: useful...
-void COM_ToLowerString(const char *in, char *out);
-void COM_ToUpperString(const char *in, char *out);
+void COM_ToLowerString (const char *in, char *out, size_t size_out);
+void COM_ToUpperString (const char *in, char *out, size_t size_out);
int COM_StringBeginsWith(const char *s, const char *match);
typedef struct stringlist_s
FS_StripExtension
============
*/
-void FS_StripExtension (const char *in, char *out)
+void FS_StripExtension (const char *in, char *out, size_t size_out)
{
char *last = NULL;
- while (*in)
+
+ if (size_out == 0)
+ return;
+
+ while (*in && size_out > 1)
{
if (*in == '.')
last = out;
else if (*in == '/' || *in == '\\' || *in == ':')
last = NULL;
*out++ = *in++;
+ size_out--;
}
if (last)
*last = 0;
// ------ Other functions ------ //
-void FS_StripExtension (const char *in, char *out);
+void FS_StripExtension (const char *in, char *out, size_t size_out);
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
else // LordHavoc: bsp version 29 (normal white lighting)
{
// LordHavoc: hope is not lost yet, check for a .lit file to load
- strcpy(litfilename, loadmodel->name);
- FS_StripExtension(litfilename, litfilename);
- strcat(litfilename, ".lit");
+ strlcpy (litfilename, loadmodel->name, sizeof (litfilename));
+ FS_StripExtension (litfilename, litfilename, sizeof (litfilename));
+ strlcat (litfilename, ".lit", sizeof (litfilename));
data = (qbyte*) FS_LoadFile(litfilename, false);
if (data)
{
char lightsfilename[1024], *s, *t, *lightsstring;
mlight_t *e;
- strcpy(lightsfilename, loadmodel->name);
- FS_StripExtension(lightsfilename, lightsfilename);
- strcat(lightsfilename, ".lights");
+ strlcpy (lightsfilename, loadmodel->name, sizeof (lightsfilename));
+ FS_StripExtension (lightsfilename, lightsfilename, sizeof(lightsfilename));
+ strlcat (lightsfilename, ".lights", sizeof (lightsfilename));
s = lightsstring = (char *) FS_LoadFile(lightsfilename, false);
if (s)
{
Con_Printf("No map loaded.\n");
return;
}
- FS_StripExtension(cl.worldmodel->name, name);
- strcat(name, ".rtlights");
+ FS_StripExtension (cl.worldmodel->name, name, sizeof (name));
+ strlcat (name, ".rtlights", sizeof (name));
lightsstring = FS_LoadFile(name, false);
if (lightsstring)
{
Con_Printf("No map loaded.\n");
return;
}
- FS_StripExtension(cl.worldmodel->name, name);
- strcat(name, ".rtlights");
+ FS_StripExtension (cl.worldmodel->name, name, sizeof (name));
+ strlcat (name, ".rtlights", sizeof (name));
bufchars = bufmaxchars = 0;
buf = NULL;
for (light = r_shadow_worldlightchain;light;light = light->next)
Con_Printf("No map loaded.\n");
return;
}
- FS_StripExtension(cl.worldmodel->name, name);
- strcat(name, ".lights");
+ FS_StripExtension (cl.worldmodel->name, name, sizeof (name));
+ strlcat (name, ".lights", sizeof (name));
lightsstring = FS_LoadFile(name, false);
if (lightsstring)
{