]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
fix a few clang warnings that try to hint to buffer overruns
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 10 Feb 2012 14:00:04 +0000 (14:00 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 10 Feb 2012 14:00:04 +0000 (14:00 +0000)
except that these were not overruns (see context in code), but just redundant
strlen calls for allocating and then copying

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11673 d7cf8633-e32d-0410-b094-e92efae38249

cl_parse.c
console.c
fs.c

index 5f97c53aa23fc08f95294c0dea1a4a6c5de82f58..a464db893b4e17a2ba10b984fd4a3133d388638b 100644 (file)
@@ -2947,6 +2947,7 @@ static void CL_IPLog_Load(void);
 static void CL_IPLog_Add(const char *address, const char *name, qboolean checkexisting, qboolean addtofile)
 {
        int i;
 static void CL_IPLog_Add(const char *address, const char *name, qboolean checkexisting, qboolean addtofile)
 {
        int i;
+       size_t sz_name, sz_address;
        if (!address || !address[0] || !name || !name[0])
                return;
        if (!cl_iplog_loaded)
        if (!address || !address[0] || !name || !name[0])
                return;
        if (!cl_iplog_loaded)
@@ -2979,12 +2980,14 @@ static void CL_IPLog_Add(const char *address, const char *name, qboolean checkex
                        Mem_Free(olditems);
                }
        }
                        Mem_Free(olditems);
                }
        }
-       cl_iplog_items[cl_iplog_numitems].address = (char *) Mem_Alloc(cls.permanentmempool, strlen(address) + 1);
-       cl_iplog_items[cl_iplog_numitems].name = (char *) Mem_Alloc(cls.permanentmempool, strlen(name) + 1);
-       strlcpy(cl_iplog_items[cl_iplog_numitems].address, address, strlen(address) + 1);
+       sz_address = strlen(address) + 1;
+       sz_name = strlen(name) + 1;
+       cl_iplog_items[cl_iplog_numitems].address = (char *) Mem_Alloc(cls.permanentmempool, sz_address);
+       cl_iplog_items[cl_iplog_numitems].name = (char *) Mem_Alloc(cls.permanentmempool, sz_name);
+       strlcpy(cl_iplog_items[cl_iplog_numitems].address, address, sz_address);
        // TODO: maybe it would be better to strip weird characters from name when
        // copying it here rather than using a straight strcpy?
        // TODO: maybe it would be better to strip weird characters from name when
        // copying it here rather than using a straight strcpy?
-       strlcpy(cl_iplog_items[cl_iplog_numitems].name, name, strlen(name) + 1);
+       strlcpy(cl_iplog_items[cl_iplog_numitems].name, name, sz_name);
        cl_iplog_numitems++;
        if (addtofile)
        {
        cl_iplog_numitems++;
        if (addtofile)
        {
index 831c30a9f35a8dbfdff36f1e52ad53590e74ef25..46b5840574c8922873cec49da297d7948af55bc0 100644 (file)
--- a/console.c
+++ b/console.c
@@ -2485,7 +2485,7 @@ static void Nicks_CutMatchesAlphaNumeric(int count)
        if(Nicks_strcleanlen(Nicks_sanlist[0]) < strlen(tempstr))
        {
                // if the clean sanitized one is longer than the current one, use it, it has crap chars which definitely are in there
        if(Nicks_strcleanlen(Nicks_sanlist[0]) < strlen(tempstr))
        {
                // if the clean sanitized one is longer than the current one, use it, it has crap chars which definitely are in there
-               strlcpy(Nicks_sanlist[0], tempstr, sizeof(tempstr));
+               strlcpy(Nicks_sanlist[0], tempstr, sizeof(Nicks_sanlist[0]));
        }
 }
 
        }
 }
 
@@ -2541,7 +2541,7 @@ static void Nicks_CutMatchesNoSpaces(int count)
        if(Nicks_strcleanlen(Nicks_sanlist[0]) < strlen(tempstr))
        {
                // if the clean sanitized one is longer than the current one, use it, it has crap chars which definitely are in there
        if(Nicks_strcleanlen(Nicks_sanlist[0]) < strlen(tempstr))
        {
                // if the clean sanitized one is longer than the current one, use it, it has crap chars which definitely are in there
-               strlcpy(Nicks_sanlist[0], tempstr, sizeof(tempstr));
+               strlcpy(Nicks_sanlist[0], tempstr, sizeof(Nicks_sanlist[0]));
        }
 }
 
        }
 }
 
diff --git a/fs.c b/fs.c
index 93768046d58dbe73e3b2049bb121e55ae920d893..e21a58395b99b6c775903f96bdda2ce20e5f8234 100644 (file)
--- a/fs.c
+++ b/fs.c
@@ -1722,10 +1722,11 @@ void FS_Init_SelfPack (void)
                                p = buf;
                                while(COM_ParseToken_Console(&p))
                                {
                                p = buf;
                                while(COM_ParseToken_Console(&p))
                                {
+                                       size_t sz = strlen(com_token) + 1; // shut up clang
                                        if(i >= args_left)
                                                break;
                                        if(i >= args_left)
                                                break;
-                                       q = (char *)Mem_Alloc(fs_mempool, strlen(com_token) + 1);
-                                       strlcpy(q, com_token, strlen(com_token) + 1);
+                                       q = (char *)Mem_Alloc(fs_mempool, sz);
+                                       strlcpy(q, com_token, sz);
                                        new_argv[com_argc + i] = q;
                                        ++i;
                                }
                                        new_argv[com_argc + i] = q;
                                        ++i;
                                }