diff options
Diffstat (limited to 'indra/llcommon')
-rw-r--r-- | indra/llcommon/llpreprocessor.h | 6 | ||||
-rw-r--r-- | indra/llcommon/llprocessor.cpp | 22 | ||||
-rw-r--r-- | indra/llcommon/llstring.cpp | 27 | ||||
-rw-r--r-- | indra/llcommon/llstring.h | 4 | ||||
-rw-r--r-- | indra/llcommon/llsys.cpp | 4 | ||||
-rw-r--r-- | indra/llcommon/lluuidhashmap.h | 10 |
6 files changed, 56 insertions, 17 deletions
diff --git a/indra/llcommon/llpreprocessor.h b/indra/llcommon/llpreprocessor.h index 8fa171c482..aaecbf3ddc 100644 --- a/indra/llcommon/llpreprocessor.h +++ b/indra/llcommon/llpreprocessor.h @@ -62,9 +62,9 @@ #endif // Deal with the differeneces on Windows -#if defined(LL_WINDOWS) -#define snprintf _snprintf /*Flawfinder: ignore*/ -#endif // LL_WINDOWS +#if LL_WINDOWS +#define snprintf safe_snprintf /* Flawfinder: ignore */ +#endif // LL_WINDOWS // Static linking with apr on windows needs to be declared. #ifdef LL_WINDOWS diff --git a/indra/llcommon/llprocessor.cpp b/indra/llcommon/llprocessor.cpp index a044710195..a941941fa8 100644 --- a/indra/llcommon/llprocessor.cpp +++ b/indra/llcommon/llprocessor.cpp @@ -598,7 +598,7 @@ bool CProcessor::AnalyzeIntelProcessor() else { // If there's no serial number support we just put "No serial number" - snprintf( /* Flawfinder: ignore */ + snprintf( /* Flawfinder: ignore */ CPUInfo.strProcessorSerial, sizeof(CPUInfo.strProcessorSerial), "No Processor Serial Number"); @@ -974,7 +974,7 @@ bool CProcessor::AnalyzeAMDProcessor() if ((ecxreg >> 24) > 0) { CPUInfo._L1.Data.bPresent = true; - snprintf(CPUInfo._L1.Data.strSize, sizeof(CPUInfo._L1.Data.strSize), "%d KB", ecxreg >> 24); /*Flawfinder: ignore*/ + snprintf(CPUInfo._L1.Data.strSize, sizeof(CPUInfo._L1.Data.strSize), "%d KB", ecxreg >> 24); /* Flawfinder: ignore */ CPUInfo._L1.Data.uiAssociativeWays = (ecxreg >> 15) & 0xFF; CPUInfo._L1.Data.uiLineSize = ecxreg & 0xFF; } @@ -982,7 +982,7 @@ bool CProcessor::AnalyzeAMDProcessor() if ((edxreg >> 24) > 0) { CPUInfo._L1.Instruction.bPresent = true; - snprintf(CPUInfo._L1.Instruction.strSize, sizeof(CPUInfo._L1.Instruction.strSize), "%d KB", edxreg >> 24); /*Flawfinder: ignore*/ + snprintf(CPUInfo._L1.Instruction.strSize, sizeof(CPUInfo._L1.Instruction.strSize), "%d KB", edxreg >> 24); /* Flawfinder: ignore */ CPUInfo._L1.Instruction.uiAssociativeWays = (edxreg >> 15) & 0xFF; CPUInfo._L1.Instruction.uiLineSize = edxreg & 0xFF; } @@ -1006,7 +1006,7 @@ bool CProcessor::AnalyzeAMDProcessor() if (((ecxreg >> 12) & 0xF) > 0) { CPUInfo._L2.bPresent = true; - snprintf(CPUInfo._L2.strSize, sizeof(CPUInfo._L2.strSize), "%d KB", ecxreg >> 16); /*Flawfinder: ignore*/ + snprintf(CPUInfo._L2.strSize, sizeof(CPUInfo._L2.strSize), "%d KB", ecxreg >> 16); /* Flawfinder: ignore */ switch ((ecxreg >> 12) & 0xF) { case 1: @@ -1099,9 +1099,9 @@ bool CProcessor::AnalyzeUnknownProcessor() strcpy(CPUInfo.strProcessorSerial, "Unknown / Not supported"); /*Flawfinder: ignore*/ // For the family, model and brand id we can only print the numeric value - snprintf(CPUInfo.strBrandID, sizeof(CPUInfo.strBrandID), "Brand-ID number %d", CPUInfo.uiBrandID); /*Flawfinder: ignore*/ - snprintf(CPUInfo.strFamily, sizeof(CPUInfo.strFamily), "Family number %d", CPUInfo.uiFamily); /*Flawfinder: ignore*/ - snprintf(CPUInfo.strModel, sizeof(CPUInfo.strModel), "Model number %d", CPUInfo.uiModel); /*Flawfinder: ignore*/ + snprintf(CPUInfo.strBrandID, sizeof(CPUInfo.strBrandID), "Brand-ID number %d", CPUInfo.uiBrandID); /* Flawfinder: ignore */ + snprintf(CPUInfo.strFamily, sizeof(CPUInfo.strFamily), "Family number %d", CPUInfo.uiFamily); /* Flawfinder: ignore */ + snprintf(CPUInfo.strModel, sizeof(CPUInfo.strModel), "Model number %d", CPUInfo.uiModel); /* Flawfinder: ignore */ // Nevertheless we can determine the processor type switch (CPUInfo.uiType) @@ -1951,7 +1951,7 @@ const ProcessorInfo *CProcessor::GetCPUInfo() if(l1dcachesize != 0) { CPUInfo._L1.Data.bPresent = true; - snprintf(CPUInfo._L1.Data.strSize, sizeof(CPUInfo._L1.Data.strSize), "%d KB", l1dcachesize / 1024); /* Flawfinder: ignore */ + snprintf(CPUInfo._L1.Data.strSize, sizeof(CPUInfo._L1.Data.strSize), "%d KB", l1dcachesize / 1024); /* Flawfinder: ignore */ // CPUInfo._L1.Data.uiAssociativeWays = ???; CPUInfo._L1.Data.uiLineSize = cachelinesize; } @@ -1959,7 +1959,7 @@ const ProcessorInfo *CProcessor::GetCPUInfo() if(l1icachesize != 0) { CPUInfo._L1.Instruction.bPresent = true; - snprintf(CPUInfo._L1.Instruction.strSize, sizeof(CPUInfo._L1.Instruction.strSize), "%d KB", l1icachesize / 1024); /* Flawfinder: ignore */ + snprintf(CPUInfo._L1.Instruction.strSize, sizeof(CPUInfo._L1.Instruction.strSize), "%d KB", l1icachesize / 1024); /* Flawfinder: ignore */ // CPUInfo._L1.Instruction.uiAssociativeWays = ???; CPUInfo._L1.Instruction.uiLineSize = cachelinesize; } @@ -1967,7 +1967,7 @@ const ProcessorInfo *CProcessor::GetCPUInfo() if(l2cachesize != 0) { CPUInfo._L2.bPresent = true; - snprintf(CPUInfo._L2.strSize, sizeof(CPUInfo._L2.strSize), "%d KB", l2cachesize / 1024); /* Flawfinder: ignore */ + snprintf(CPUInfo._L2.strSize, sizeof(CPUInfo._L2.strSize), "%d KB", l2cachesize / 1024); /* Flawfinder: ignore */ // CPUInfo._L2.uiAssociativeWays = ???; CPUInfo._L2.uiLineSize = cachelinesize; } @@ -1975,7 +1975,7 @@ const ProcessorInfo *CProcessor::GetCPUInfo() if(l3cachesize != 0) { CPUInfo._L2.bPresent = true; - snprintf(CPUInfo._L2.strSize, sizeof(CPUInfo._L2.strSize), "%d KB", l3cachesize / 1024); /* Flawfinder: ignore */ + snprintf(CPUInfo._L2.strSize, sizeof(CPUInfo._L2.strSize), "%d KB", l3cachesize / 1024); /* Flawfinder: ignore */ // CPUInfo._L2.uiAssociativeWays = ???; CPUInfo._L2.uiLineSize = cachelinesize; } diff --git a/indra/llcommon/llstring.cpp b/indra/llcommon/llstring.cpp index 767a72dfe9..c6f436a5bb 100644 --- a/indra/llcommon/llstring.cpp +++ b/indra/llcommon/llstring.cpp @@ -654,6 +654,33 @@ std::string mbcsstring_makeASCII(const std::string& wstr) return out_str; } +#if LL_WINDOWS +/* If the size of the passed in buffer is not large enough to hold the string, + * two bad things happen: + * 1. resulting formatted string is NOT null terminated + * 2. Depending on the platform, the return value could be a) the required + * size of the buffer to copy the entire formatted string or b) -1. + * On Windows with VS.Net 2003, it returns -1 e.g. + * + * safe_snprintf always adds a NULL terminator so that the caller does not + * need to check for return value or need to add the NULL terminator. + * It does not, however change the return value - to let the caller know + * that the passed in buffer size was not large enough to hold the formatted string. + * + */ +int safe_snprintf(char *str, size_t size, const char *format, ...) +{ + va_list args; + va_start(args, format); + + int num_written = _vsnprintf(str, size, format, args); /* Flawfinder: ignore */ + va_end(args); + + str[size-1] = '\0'; // always null terminate + return num_written; +} +#endif // LL_WINDOWS + S32 LLStringOps::collate(const llwchar* a, const llwchar* b) { #if LL_WINDOWS diff --git a/indra/llcommon/llstring.h b/indra/llcommon/llstring.h index 6e9ea0b5a0..cbfc2a2a75 100644 --- a/indra/llcommon/llstring.h +++ b/indra/llcommon/llstring.h @@ -19,6 +19,7 @@ #include <stdlib.h> #include <errno.h> #include <math.h> +#include <stdarg.h> /* for vsnprintf */ #if LL_LINUX #include <wctype.h> #include <wchar.h> @@ -445,6 +446,9 @@ std::ostream& operator<<(std::ostream &s, const LLStringBase<T> &str) std::ostream& operator<<(std::ostream &s, const LLWString &wstr); +#if LL_WINDOWS +int safe_snprintf(char *str, size_t size, const char *format, ...); +#endif // LL_WINDOWS /** * Many of the 'strip' and 'replace' methods of LLStringBase need diff --git a/indra/llcommon/llsys.cpp b/indra/llcommon/llsys.cpp index ad6f85b068..54276f9f2f 100644 --- a/indra/llcommon/llsys.cpp +++ b/indra/llcommon/llsys.cpp @@ -124,7 +124,7 @@ LLOSInfo::LLOSInfo() : } else { - snprintf( /* Flawfinder: ignore */ + snprintf( /* Flawfinder: ignore */ tmp, sizeof(tmp), "%s (Build %d)", @@ -324,7 +324,7 @@ std::string LLCPUInfo::getCPUStringTerse() const if (freq < 10000.f && freq > 200.f ) { char tmp[MAX_STRING]; /* Flawfinder: ignore */ - snprintf(tmp, sizeof(tmp), " (%.0f Mhz)", freq); /* Flawfinder: ignore */ + snprintf(tmp, sizeof(tmp), " (%.0f Mhz)", freq); /* Flawfinder: ignore */ cpu_string.append(tmp); } diff --git a/indra/llcommon/lluuidhashmap.h b/indra/llcommon/lluuidhashmap.h index f7d32b1fe0..98a269b1a4 100644 --- a/indra/llcommon/lluuidhashmap.h +++ b/indra/llcommon/lluuidhashmap.h @@ -206,7 +206,7 @@ inline S32 LLUUIDHashMap<DATA_TYPE, SIZE>::getLength() const S32 bin; for (bin = 0; bin < 256; bin++) { - LLUUIDHashNode<DATA_TYPE, SIZE>* nodep = &mNodes[bin]; + LLUUIDHashNode<DATA_TYPE, SIZE>* nodep = (LLUUIDHashNode<DATA_TYPE, SIZE>*) &mNodes[bin]; while (nodep) { count += nodep->mCount; @@ -421,6 +421,7 @@ public: ~LLUUIDHashMapIter(); + inline void reset(); inline void first(); inline void next(); inline BOOL done() const; @@ -460,10 +461,17 @@ LLUUIDHashMapIter<DATA_TYPE, SIZE>::LLUUIDHashMapIter(LLUUIDHashMap<DATA_TYPE, S template <class DATA_TYPE, int SIZE> LLUUIDHashMapIter<DATA_TYPE, SIZE>::~LLUUIDHashMapIter() { + reset(); +} + +template <class DATA_TYPE, int SIZE> +inline void LLUUIDHashMapIter<DATA_TYPE, SIZE>::reset() +{ if (mCurHashNodep) { // We're partway through an iteration, we can clean up now mHashMapp->mIterCount--; + mCurHashNodep = NULL; } } |