]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
Mostly [v]sprintf -> [v]snprintf replacements, and a couple of other fixes regarding...
authormolivier <molivier@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 1 Oct 2003 12:19:26 +0000 (12:19 +0000)
committermolivier <molivier@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 1 Oct 2003 12:19:26 +0000 (12:19 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3520 d7cf8633-e32d-0410-b094-e92efae38249

fs.c
pr_edict.c
sys_linux.c
sys_win.c

diff --git a/fs.c b/fs.c
index b0c2de1e7c924d0f741f27e63f8cd92ada5d4a93..7fe9c39a3eaa4ee640496417dc90dd938aac8fef 100644 (file)
--- a/fs.c
+++ b/fs.c
@@ -751,7 +751,7 @@ void FS_AddGameDirectory (char *dir)
        {
                if (matchpattern(current->text, "*.pak", true))
                {
-                       sprintf (pakfile, "%s/%s", dir, current->text);
+                       snprintf (pakfile, sizeof (pakfile), "%s/%s", dir, current->text);
                        pak = FS_LoadPackPAK (pakfile);
                        if (pak)
                        {
@@ -770,7 +770,7 @@ void FS_AddGameDirectory (char *dir)
        {
                if (matchpattern(current->text, "*.pk3", true))
                {
-                       sprintf (pakfile, "%s/%s", dir, current->text);
+                       snprintf (pakfile, sizeof (pakfile), "%s/%s", dir, current->text);
                        pak = FS_LoadPackPK3 (pakfile);
                        if (pak)
                        {
@@ -1061,7 +1061,7 @@ qfile_t *FS_FOpenFile (const char *filename, qboolean quiet)
                }
                else
                {
-                       sprintf (netpath, "%s/%s",search->filename, filename);
+                       snprintf (netpath, sizeof (netpath), "%s/%s",search->filename, filename);
 
                        if (!FS_SysFileExists (netpath))
                                continue;
@@ -1603,7 +1603,7 @@ qboolean FS_WriteFile (const char *filename, void *data, int len)
        FILE *handle;
        char name[MAX_OSPATH];
 
-       sprintf (name, "%s/%s", fs_gamedir, filename);
+       snprintf (name, sizeof (name), "%s/%s", fs_gamedir, filename);
 
        // Create directories up to the file
        FS_CreatePath (name);
@@ -1695,7 +1695,7 @@ qboolean FS_FileExists (const char *filename)
                }
                else
                {
-                       sprintf (netpath, "%s/%s",search->filename, filename);
+                       snprintf (netpath, sizeof (netpath), "%s/%s",search->filename, filename);
                        if (FS_SysFileExists (netpath))
                                return true;
                }
index 750c26c23d82e4829600b262508ecb70fd0e0494..11acb1418ebd74db361e6083cf50738809277ffa 100644 (file)
@@ -393,40 +393,40 @@ char *PR_ValueString (etype_t type, eval_t *val)
        switch (type)
        {
        case ev_string:
-               sprintf (line, "%s", PR_GetString(val->string));
+               snprintf (line, sizeof (line), "%s", PR_GetString(val->string));
                break;
        case ev_entity:
                //n = NoCrash_NUM_FOR_EDICT(PROG_TO_EDICT(val->edict));
                n = val->edict;
                if (n < 0 || n >= MAX_EDICTS)
-                       sprintf (line, "entity %i (invalid!)", n);
+                       snprintf (line, sizeof (line), "entity %i (invalid!)", n);
                else
-                       sprintf (line, "entity %i", n);
+                       snprintf (line, sizeof (line), "entity %i", n);
                break;
        case ev_function:
                f = pr_functions + val->function;
-               sprintf (line, "%s()", PR_GetString(f->s_name));
+               snprintf (line, sizeof (line), "%s()", PR_GetString(f->s_name));
                break;
        case ev_field:
                def = ED_FieldAtOfs ( val->_int );
-               sprintf (line, ".%s", PR_GetString(def->s_name));
+               snprintf (line, sizeof (line), ".%s", PR_GetString(def->s_name));
                break;
        case ev_void:
-               sprintf (line, "void");
+               snprintf (line, sizeof (line), "void");
                break;
        case ev_float:
                // LordHavoc: changed from %5.1f to %10.4f
-               sprintf (line, "%10.4f", val->_float);
+               snprintf (line, sizeof (line), "%10.4f", val->_float);
                break;
        case ev_vector:
                // LordHavoc: changed from %5.1f to %10.4f
-               sprintf (line, "'%10.4f %10.4f %10.4f'", val->vector[0], val->vector[1], val->vector[2]);
+               snprintf (line, sizeof (line), "'%10.4f %10.4f %10.4f'", val->vector[0], val->vector[1], val->vector[2]);
                break;
        case ev_pointer:
-               sprintf (line, "pointer");
+               snprintf (line, sizeof (line), "pointer");
                break;
        default:
-               sprintf (line, "bad type %i", type);
+               snprintf (line, sizeof (line), "bad type %i", type);
                break;
        }
 
@@ -454,14 +454,14 @@ char *PR_UglyValueString (etype_t type, eval_t *val)
        switch (type)
        {
        case ev_string:
-               sprintf (line, "%s", PR_GetString(val->string));
+               snprintf (line, sizeof (line), "%s", PR_GetString(val->string));
                break;
        case ev_entity:
-               sprintf (line, "%i", NUM_FOR_EDICT(PROG_TO_EDICT(val->edict)));
+               snprintf (line, sizeof (line), "%i", NUM_FOR_EDICT(PROG_TO_EDICT(val->edict)));
                break;
        case ev_function:
                f = pr_functions + val->function;
-               sprintf (line, "%s", PR_GetString(f->s_name));
+               snprintf (line, sizeof (line), "%s", PR_GetString(f->s_name));
                break;
        case ev_field:
                def = ED_FieldAtOfs ( val->_int );
@@ -470,7 +470,7 @@ char *PR_UglyValueString (etype_t type, eval_t *val)
                // this fixes saving games from various mods
                //sprintf (line, "%s", PR_GetString(def->s_name));
                s = PR_GetString(def->s_name);
-               for (i = 0;i < 4095 && *s;)
+               for (i = 0;i < sizeof (line) - 2 && *s;)
                {
                        if (*s == '\n')
                        {
@@ -483,22 +483,22 @@ char *PR_UglyValueString (etype_t type, eval_t *val)
                                line[i++] = 'r';
                        }
                        else
-                               line[i] = *s;
+                               line[i++] = *s;
                        s++;
                }
-               line[i++] = 0;
+               line[i] = '\0';
                break;
        case ev_void:
-               sprintf (line, "void");
+               snprintf (line, sizeof (line), "void");
                break;
        case ev_float:
-               sprintf (line, "%f", val->_float);
+               snprintf (line, sizeof (line), "%f", val->_float);
                break;
        case ev_vector:
-               sprintf (line, "%f %f %f", val->vector[0], val->vector[1], val->vector[2]);
+               snprintf (line, sizeof (line), "%f %f %f", val->vector[0], val->vector[1], val->vector[2]);
                break;
        default:
-               sprintf (line, "bad type %i", type);
+               snprintf (line, sizeof (line), "bad type %i", type);
                break;
        }
 
@@ -586,7 +586,7 @@ void ED_Print (edict_t *ed)
        }
 
        tempstring[0] = 0;
-       sprintf(tempstring, "\nEDICT %i:\n", NUM_FOR_EDICT(ed));
+       snprintf (tempstring, sizeof (tempstring), "\nEDICT %i:\n", NUM_FOR_EDICT(ed));
        for (i=1 ; i<progs->numfielddefs ; i++)
        {
                d = &pr_fielddefs[i];
@@ -996,19 +996,15 @@ const char *ED_ParseEdict (const char *data, edict_t *ent)
 
                // anglehack is to allow QuakeEd to write single scalar angles
                // and allow them to be turned into vectors. (FIXME...)
-               if (!strcmp(com_token, "angle"))
-               {
-                       strcpy (com_token, "angles");
-                       anglehack = true;
-               }
-               else
-                       anglehack = false;
+               anglehack = !strcmp (com_token, "angle");
+               if (anglehack)
+                       strlcpy (com_token, "angles", sizeof (com_token));
 
                // 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 heynames with trailing spaces
                n = strlen(keyname);
@@ -1042,8 +1038,8 @@ const char *ED_ParseEdict (const char *data, edict_t *ent)
                if (anglehack)
                {
                        char    temp[32];
-                       strcpy (temp, com_token);
-                       sprintf (com_token, "0 %s 0", temp);
+                       strlcpy (temp, com_token, sizeof (temp));
+                       snprintf (com_token, sizeof (com_token), "0 %s 0", temp);
                }
 
                if (!ED_ParseEpair(ent, key, com_token))
index 084eb0402cb7ad0b0112c3f85aa5f63ab0b92a62..728ff5fd57bde6bdc2f91bbefa569d1e9bd07c95 100644 (file)
@@ -43,7 +43,7 @@ void Sys_Error (const char *error, ...)
 #endif
 
        va_start (argptr,error);
-       vsprintf (string,error,argptr);
+       vsnprintf (string, sizeof (string), error, argptr);
        va_end (argptr);
        fprintf(stderr, "Error: %s\n", string);
 
index d9b013b0bd8471ac2c9d6e882776ae4010c48cbf..d53955d15875311f047a572e095c37fba228c064 100644 (file)
--- a/sys_win.c
+++ b/sys_win.c
@@ -63,7 +63,7 @@ void Sys_Error (const char *error, ...)
        static int      in_sys_error2 = 0;
 
        va_start (argptr, error);
-       vsprintf (text, error, argptr);
+       vsnprintf (text, sizeof (text), error, argptr);
        va_end (argptr);
 
        // close video so the message box is visible, unless we already tried that