From cd74b7ea315a2d7e8f9210578e2eee57e5adc3dd Mon Sep 17 00:00:00 2001 From: divverent Date: Fri, 10 Feb 2012 14:00:04 +0000 Subject: [PATCH] fix a few clang warnings that try to hint to buffer overruns 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 | 11 +++++++---- console.c | 4 ++-- fs.c | 5 +++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/cl_parse.c b/cl_parse.c index 5f97c53a..a464db89 100644 --- a/cl_parse.c +++ b/cl_parse.c @@ -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; + size_t sz_name, sz_address; 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); } } - 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? - 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) { diff --git a/console.c b/console.c index 831c30a9..46b58405 100644 --- 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 - 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 - 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 93768046..e21a5839 100644 --- a/fs.c +++ b/fs.c @@ -1722,10 +1722,11 @@ void FS_Init_SelfPack (void) p = buf; while(COM_ParseToken_Console(&p)) { + size_t sz = strlen(com_token) + 1; // shut up clang 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; } -- 2.39.2