diff options
author | Ansariel <ansariel.hiller@phoenixviewer.com> | 2024-06-01 15:49:26 +0200 |
---|---|---|
committer | Ansariel <ansariel.hiller@phoenixviewer.com> | 2024-06-01 15:49:26 +0200 |
commit | b42f9d836b4c0f7fbd4bdae1734021e2a09fdbe8 (patch) | |
tree | d73404c2fbacce379a57e2d03a6cd54558590859 /indra/llcommon | |
parent | cb3bd8865aa0f9fb8a247ea595cf1973057ba91f (diff) |
Re-enable a lot of compiler warnings for MSVC and address the C4267 "possible loss of precision" warnings
Diffstat (limited to 'indra/llcommon')
-rw-r--r-- | indra/llcommon/llapp.cpp | 12 | ||||
-rw-r--r-- | indra/llcommon/llfile.cpp | 2 | ||||
-rw-r--r-- | indra/llcommon/llindexedvector.h | 8 | ||||
-rw-r--r-- | indra/llcommon/llpreprocessor.h | 17 | ||||
-rw-r--r-- | indra/llcommon/llqueuedthread.cpp | 2 | ||||
-rw-r--r-- | indra/llcommon/llsdserialize.cpp | 8 | ||||
-rw-r--r-- | indra/llcommon/llstl.h | 2 | ||||
-rw-r--r-- | indra/llcommon/llstring.cpp | 12 | ||||
-rw-r--r-- | indra/llcommon/tests/commonmisc_test.cpp | 6 | ||||
-rw-r--r-- | indra/llcommon/tests/lleventdispatcher_test.cpp | 8 | ||||
-rw-r--r-- | indra/llcommon/tests/llsdserialize_test.cpp | 18 |
11 files changed, 39 insertions, 56 deletions
diff --git a/indra/llcommon/llapp.cpp b/indra/llcommon/llapp.cpp index 1388e81656..99ca0f740a 100644 --- a/indra/llcommon/llapp.cpp +++ b/indra/llcommon/llapp.cpp @@ -199,9 +199,9 @@ bool LLApp::parseCommandOptions(int argc, char** argv) #if LL_WINDOWS //Windows changed command line parsing. Deal with it. - S32 slen = value.length() - 1; - S32 start = 0; - S32 end = slen; + size_t slen = value.length() - 1; + size_t start = 0; + size_t end = slen; if (argv[ii][start]=='"')start++; if (argv[ii][end]=='"')end--; if (start!=0 || end!=slen) @@ -264,9 +264,9 @@ bool LLApp::parseCommandOptions(int argc, wchar_t** wargv) #if LL_WINDOWS //Windows changed command line parsing. Deal with it. - S32 slen = value.length() - 1; - S32 start = 0; - S32 end = slen; + size_t slen = value.length() - 1; + size_t start = 0; + size_t end = slen; if (wargv[ii][start]=='"')start++; if (wargv[ii][end]=='"')end--; if (start!=0 || end!=slen) diff --git a/indra/llcommon/llfile.cpp b/indra/llcommon/llfile.cpp index 1877dd54ed..6fdf58a99b 100644 --- a/indra/llcommon/llfile.cpp +++ b/indra/llcommon/llfile.cpp @@ -345,7 +345,7 @@ const char *LLFile::tmpdir() sep = '\\'; std::vector<wchar_t> utf16path(MAX_PATH + 1); - GetTempPathW(utf16path.size(), &utf16path[0]); + GetTempPathW(static_cast<DWORD>(utf16path.size()), &utf16path[0]); utf8path = ll_convert_wide_to_string(&utf16path[0]); #else sep = '/'; diff --git a/indra/llcommon/llindexedvector.h b/indra/llcommon/llindexedvector.h index de3ae0dcc4..0b2e9c76ca 100644 --- a/indra/llcommon/llindexedvector.h +++ b/indra/llcommon/llindexedvector.h @@ -47,7 +47,7 @@ public: typedef typename std::vector<Type>::size_type size_type; protected: std::vector<Type> mVector; - std::map<Key, U32> mIndexMap; + std::map<Key, size_t> mIndexMap; public: LLIndexedVector() { mVector.reserve(BlockSize); } @@ -68,10 +68,10 @@ public: Type& operator[](const Key& k) { - typename std::map<Key, U32>::const_iterator iter = mIndexMap.find(k); + typename std::map<Key, size_t>::const_iterator iter = mIndexMap.find(k); if (iter == mIndexMap.end()) { - U32 n = mVector.size(); + auto n = mVector.size(); mIndexMap[k] = n; mVector.push_back(Type()); llassert(mVector.size() == mIndexMap.size()); @@ -85,7 +85,7 @@ public: const_iterator find(const Key& k) const { - typename std::map<Key, U32>::const_iterator iter = mIndexMap.find(k); + typename std::map<Key, size_t>::const_iterator iter = mIndexMap.find(k); if(iter == mIndexMap.end()) { return mVector.end(); diff --git a/indra/llcommon/llpreprocessor.h b/indra/llcommon/llpreprocessor.h index 6b6bd063ab..0c5799ad96 100644 --- a/indra/llcommon/llpreprocessor.h +++ b/indra/llcommon/llpreprocessor.h @@ -122,23 +122,6 @@ // Deal with VC6 problems #if LL_MSVC -#pragma warning( 3 : 4701 ) // "local variable used without being initialized" Treat this as level 3, not level 4. -#pragma warning( 3 : 4702 ) // "unreachable code" Treat this as level 3, not level 4. -#pragma warning( 3 : 4189 ) // "local variable initialized but not referenced" Treat this as level 3, not level 4. -//#pragma warning( 3 : 4018 ) // "signed/unsigned mismatch" Treat this as level 3, not level 4. -#pragma warning( 3 : 4263 ) // 'function' : member function does not override any base class virtual member function -#pragma warning( 3 : 4264 ) // "'virtual_function' : no override available for virtual member function from base 'class'; function is hidden" -#pragma warning( 3 : 4265 ) // "class has virtual functions, but destructor is not virtual" -#pragma warning( 3 : 4266 ) // 'function' : no override available for virtual member function from base 'type'; function is hidden -#pragma warning (disable : 4180) // qualifier applied to function type has no meaning; ignored -//#pragma warning( disable : 4284 ) // silly MS warning deep inside their <map> include file - -#if ADDRESS_SIZE == 64 -// That one is all over the place for x64 builds. -#pragma warning( disable : 4267 ) // 'var' : conversion from 'size_t' to 'type', possible loss of data) -#endif - -#pragma warning( disable : 4503 ) // 'decorated name length exceeded, name was truncated'. Does not seem to affect compilation. #pragma warning( disable : 4996 ) // warning: deprecated // Linker optimization with "extern template" generates these warnings diff --git a/indra/llcommon/llqueuedthread.cpp b/indra/llcommon/llqueuedthread.cpp index 39e8113587..7d77f6f6a9 100644 --- a/indra/llcommon/llqueuedthread.cpp +++ b/indra/llcommon/llqueuedthread.cpp @@ -210,7 +210,7 @@ void LLQueuedThread::waitOnPending() // MAIN thread void LLQueuedThread::printQueueStats() { - U32 size = mRequestQueue.size(); + auto size = mRequestQueue.size(); if (size > 0) { LL_INFOS() << llformat("Pending Requests:%d ", mRequestQueue.size()) << LL_ENDL; diff --git a/indra/llcommon/llsdserialize.cpp b/indra/llcommon/llsdserialize.cpp index 92d9392477..15002580c9 100644 --- a/indra/llcommon/llsdserialize.cpp +++ b/indra/llcommon/llsdserialize.cpp @@ -1546,7 +1546,7 @@ S32 LLSDBinaryFormatter::format_impl(const LLSD& data, std::ostream& ostr, case LLSD::TypeMap: { ostr.put('{'); - U32 size_nbo = htonl(data.size()); + U32 size_nbo = htonl(static_cast<u_long>(data.size())); ostr.write((const char*)(&size_nbo), sizeof(U32)); LLSD::map_const_iterator iter = data.beginMap(); LLSD::map_const_iterator end = data.endMap(); @@ -1563,7 +1563,7 @@ S32 LLSDBinaryFormatter::format_impl(const LLSD& data, std::ostream& ostr, case LLSD::TypeArray: { ostr.put('['); - U32 size_nbo = htonl(data.size()); + U32 size_nbo = htonl(static_cast<u_long>(data.size())); ostr.write((const char*)(&size_nbo), sizeof(U32)); LLSD::array_const_iterator iter = data.beginArray(); LLSD::array_const_iterator end = data.endArray(); @@ -1630,7 +1630,7 @@ S32 LLSDBinaryFormatter::format_impl(const LLSD& data, std::ostream& ostr, { ostr.put('b'); const std::vector<U8>& buffer = data.asBinary(); - U32 size_nbo = htonl(buffer.size()); + U32 size_nbo = htonl(static_cast<u_long>(buffer.size())); ostr.write((const char*)(&size_nbo), sizeof(U32)); if(buffer.size()) ostr.write((const char*)&buffer[0], buffer.size()); break; @@ -1648,7 +1648,7 @@ void LLSDBinaryFormatter::formatString( const std::string& string, std::ostream& ostr) const { - U32 size_nbo = htonl(string.size()); + U32 size_nbo = htonl(static_cast<u_long>(string.size())); ostr.write((const char*)(&size_nbo), sizeof(U32)); ostr.write(string.c_str(), string.size()); } diff --git a/indra/llcommon/llstl.h b/indra/llcommon/llstl.h index 67b4c141af..1b52d94258 100644 --- a/indra/llcommon/llstl.h +++ b/indra/llcommon/llstl.h @@ -326,7 +326,7 @@ inline bool vector_replace_with_last(std::vector<T>& invec, const T& val) template <typename T> inline T* vector_append(std::vector<T>& invec, S32 N) { - U32 sz = invec.size(); + auto sz = invec.size(); invec.resize(sz+N); return &(invec[sz]); } diff --git a/indra/llcommon/llstring.cpp b/indra/llcommon/llstring.cpp index 5df0f8702d..514d73b24b 100644 --- a/indra/llcommon/llstring.cpp +++ b/indra/llcommon/llstring.cpp @@ -809,7 +809,7 @@ std::string ll_convert_wide_to_string(const wchar_t* in, size_t len_in, unsigned code_page, 0, in, - len_in, + static_cast<int>(len_in), NULL, 0, 0, @@ -824,7 +824,7 @@ std::string ll_convert_wide_to_string(const wchar_t* in, size_t len_in, unsigned code_page, 0, in, - len_in, + static_cast<int>(len_in), pout, len_out, 0, @@ -851,8 +851,8 @@ std::wstring ll_convert_string_to_wide(const char* in, size_t len, unsigned int std::vector<wchar_t> w_out(len + 1); memset(&w_out[0], 0, w_out.size()); - int real_output_str_len = MultiByteToWideChar(code_page, 0, in, len, - &w_out[0], w_out.size() - 1); + int real_output_str_len = MultiByteToWideChar(code_page, 0, in, static_cast<int>(len), + &w_out[0], static_cast<int>(w_out.size() - 1)); //looks like MultiByteToWideChar didn't add null terminator to converted string, see EXT-4858. w_out[real_output_str_len] = 0; @@ -943,7 +943,7 @@ std::optional<std::wstring> llstring_getoptenv(const std::string& key) auto wkey = ll_convert_string_to_wide(key); // Take a wild guess as to how big the buffer should be. std::vector<wchar_t> buffer(1024); - auto n = GetEnvironmentVariableW(wkey.c_str(), &buffer[0], buffer.size()); + auto n = GetEnvironmentVariableW(wkey.c_str(), &buffer[0], static_cast<DWORD>(buffer.size())); // If our initial guess was too short, n will indicate the size (in // wchar_t's) that buffer should have been, including the terminating nul. if (n > (buffer.size() - 1)) @@ -951,7 +951,7 @@ std::optional<std::wstring> llstring_getoptenv(const std::string& key) // make it big enough buffer.resize(n); // and try again - n = GetEnvironmentVariableW(wkey.c_str(), &buffer[0], buffer.size()); + n = GetEnvironmentVariableW(wkey.c_str(), &buffer[0], static_cast<DWORD>(buffer.size())); } // did that (ultimately) succeed? if (n) diff --git a/indra/llcommon/tests/commonmisc_test.cpp b/indra/llcommon/tests/commonmisc_test.cpp index 3deb864c0c..0057a1f639 100644 --- a/indra/llcommon/tests/commonmisc_test.cpp +++ b/indra/llcommon/tests/commonmisc_test.cpp @@ -67,7 +67,7 @@ namespace tut std::ostringstream resp; resp << "{'connect':true, 'position':[r128,r128,r128], 'look_at':[r0,r1,r0], 'agent_access':'M', 'region_x':i8192, 'region_y':i8192}"; std::string str = resp.str(); - LLMemoryStream mstr((U8*)str.c_str(), str.size()); + LLMemoryStream mstr((U8*)str.c_str(), static_cast<S32>(str.size())); LLSD response; S32 count = LLSDSerialize::fromNotation(response, mstr, str.size()); ensure("stream parsed", response.isDefined()); @@ -252,7 +252,7 @@ namespace tut resp << "{'label':'short binary test', 'singlebinary':b(1)\"A\", 'singlerawstring':s(1)\"A\", 'endoftest':'end' }"; std::string str = resp.str(); LLSD sd; - LLMemoryStream mstr((U8*)str.c_str(), str.size()); + LLMemoryStream mstr((U8*)str.c_str(), static_cast<S32>(str.size())); S32 count = LLSDSerialize::fromNotation(sd, mstr, str.size()); ensure_equals("parse count", count, 5); ensure("sd created", sd.isDefined()); @@ -456,7 +456,7 @@ namespace tut void mem_object::test<1>() { const char HELLO_WORLD[] = "hello world"; - LLMemoryStream mem((U8*)&HELLO_WORLD[0], strlen(HELLO_WORLD)); /* Flawfinder: ignore */ + LLMemoryStream mem((U8*)&HELLO_WORLD[0], static_cast<S32>(strlen(HELLO_WORLD))); /* Flawfinder: ignore */ std::string hello; std::string world; mem >> hello >> world; diff --git a/indra/llcommon/tests/lleventdispatcher_test.cpp b/indra/llcommon/tests/lleventdispatcher_test.cpp index a99acba848..44f772e322 100644 --- a/indra/llcommon/tests/lleventdispatcher_test.cpp +++ b/indra/llcommon/tests/lleventdispatcher_test.cpp @@ -491,7 +491,7 @@ namespace tut // Partial defaults arrays. for (LLSD::String a: ab) { - LLSD::Integer partition(std::min(partial_offset, dft_array_full[a].size())); + LLSD::Integer partition(static_cast<LLSD::Integer>(std::min(partial_offset, dft_array_full[a].size()))); dft_array_partial[a] = llsd_copy_array(dft_array_full[a].beginArray() + partition, dft_array_full[a].endArray()); @@ -508,7 +508,7 @@ namespace tut // (params, dft_array_full). Part of the point of using map-style // defaults is to allow any subset of the target function's // parameters to be optional, not just the rightmost. - for (LLSD::Integer ix = 0, ixend = params[a].size(); ix < ixend; ix += 2) + for (LLSD::Integer ix = 0, ixend = static_cast<LLSD::Integer>(params[a].size()); ix < ixend; ix += 2) { dft_map_partial[a][params[a][ix].asString()] = dft_array_full[a][ix]; } @@ -696,7 +696,7 @@ namespace tut LLSD zipmap(const LLSD& keys, const LLSD& values) { LLSD map; - for (LLSD::Integer i = 0, iend = keys.size(); i < iend; ++i) + for (LLSD::Integer i = 0, iend = static_cast<LLSD::Integer>(keys.size()); i < iend; ++i) { // Have to select asString() since you can index an LLSD // object with either String or Integer. @@ -955,7 +955,7 @@ namespace tut allreq[a] = zipmap(params[a], LLSD::emptyArray()); // Same for leftreq, save that we use the subset of the params not // supplied by dft_array_partial[a]. - LLSD::Integer partition(params[a].size() - dft_array_partial[a].size()); + LLSD::Integer partition(static_cast<LLSD::Integer>(params[a].size() - dft_array_partial[a].size())); leftreq[a] = zipmap(llsd_copy_array(params[a].beginArray(), params[a].beginArray() + partition), LLSD::emptyArray()); diff --git a/indra/llcommon/tests/llsdserialize_test.cpp b/indra/llcommon/tests/llsdserialize_test.cpp index 56fdc51e82..fb2af1d2db 100644 --- a/indra/llcommon/tests/llsdserialize_test.cpp +++ b/indra/llcommon/tests/llsdserialize_test.cpp @@ -701,7 +701,7 @@ namespace tut "<key>cam</key><real>1.23</real>" "</map></llsd>", v, - v.size() + 1); + static_cast<S32>(v.size()) + 1); } template<> template<> @@ -721,7 +721,7 @@ namespace tut "<key>cam</key><real>1.23</real>" "</map></llsd>", v, - v.size() + 1); + static_cast<S32>(v.size()) + 1); v.clear(); v["amy"] = 23; @@ -734,7 +734,7 @@ namespace tut "<key>cam</key><real>1.23</real>" "</map></llsd>", v, - v.size() + 1); + static_cast<S32>(v.size()) + 1); v.clear(); v["amy"] = 23; @@ -751,7 +751,7 @@ namespace tut "<key>cam</key><real>1.23</real>" "</map></llsd>", v, - v.size() + 1); + static_cast<S32>(v.size()) + 1); v.clear(); v[0] = 23; @@ -766,7 +766,7 @@ namespace tut "<real>1.23</real>" "</array></llsd>", v, - v.size() + 1); + static_cast<S32>(v.size()) + 1); v.clear(); v[0] = 23; @@ -782,7 +782,7 @@ namespace tut "<real>1.23</real>" "</array></llsd>", v, - v.size() + 1); + static_cast<S32>(v.size()) + 1); } template<> template<> @@ -1405,13 +1405,13 @@ namespace tut uint32_t size = htonl(1); memcpy(&vec[1], &size, sizeof(uint32_t)); vec.push_back('k'); - int key_size_loc = vec.size(); + auto key_size_loc = vec.size(); size = htonl(1); // 1 too short vec.resize(vec.size() + 4); memcpy(&vec[key_size_loc], &size, sizeof(uint32_t)); vec.push_back('a'); vec.push_back('m'); vec.push_back('y'); vec.push_back('i'); - int integer_loc = vec.size(); + auto integer_loc = vec.size(); vec.resize(vec.size() + 4); uint32_t val_int = htonl(23); memcpy(&vec[integer_loc], &val_int, sizeof(uint32_t)); @@ -1473,7 +1473,7 @@ namespace tut memcpy(&vec[1], &size, sizeof(uint32_t)); vec.push_back('"'); vec.push_back('a'); vec.push_back('m'); vec.push_back('y'); vec.push_back('"'); vec.push_back('i'); - int integer_loc = vec.size(); + auto integer_loc = vec.size(); vec.resize(vec.size() + 4); uint32_t val_int = htonl(23); memcpy(&vec[integer_loc], &val_int, sizeof(uint32_t)); |