From b0b510310028c63fa76dc60a82f771e4741376c1 Mon Sep 17 00:00:00 2001 From: Gilberto Stankiewicz <874134+kiewic@users.noreply.github.com> Date: Wed, 26 Aug 2020 02:13:13 -0700 Subject: [PATCH] Fix code analysis C4018 warnings (#3223) * Replace `auto`s with `size_t`s to reduce: ``` Severity Code Description Project File Line Suppression State Warning C4018 '<': signed/unsigned mismatch CefSharp.BrowserSubprocess.Core c:\repos\cefsharp\cefsharp.browsersubprocess.core\serialization\jsobjectsserialization.cpp 71 ``` * Fix templates --- .../Async/JavascriptAsyncMethodHandler.cpp | 2 +- .../BindObjectAsyncHandler.h | 2 +- .../Serialization/JsObjectsSerialization.cpp | 4 ++-- .../Serialization/V8Serialization.cpp | 11 ++++++----- CefSharp.Core/Internals/CefExtensionWrapper.cpp | 2 +- CefSharp.Core/Internals/CefValueWrapper.cpp | 6 +++--- CefSharp.Core/Internals/ClientAdapter.cpp | 4 ++-- .../Internals/Serialization/ObjectsSerialization.cpp | 6 +++--- CefSharp.Core/Internals/Serialization/Primitives.h | 9 +++++++++ .../Internals/Serialization/V8Serialization.h | 1 + CefSharp.Core/Internals/TypeConversion.h | 4 ++-- 11 files changed, 31 insertions(+), 20 deletions(-) diff --git a/CefSharp.BrowserSubprocess.Core/Async/JavascriptAsyncMethodHandler.cpp b/CefSharp.BrowserSubprocess.Core/Async/JavascriptAsyncMethodHandler.cpp index 7c45a4b01..790a16c94 100644 --- a/CefSharp.BrowserSubprocess.Core/Async/JavascriptAsyncMethodHandler.cpp +++ b/CefSharp.BrowserSubprocess.Core/Async/JavascriptAsyncMethodHandler.cpp @@ -54,7 +54,7 @@ namespace CefSharp auto request = CefProcessMessage::Create(kJavascriptAsyncMethodCallRequest); auto argList = request->GetArgumentList(); auto params = CefListValue::Create(); - for (auto i = 0; i < arguments.size(); i++) + for (size_t i = 0; i < arguments.size(); i++) { SerializeV8Object(arguments[i], params, i, _callbackRegistry); } diff --git a/CefSharp.BrowserSubprocess.Core/BindObjectAsyncHandler.h b/CefSharp.BrowserSubprocess.Core/BindObjectAsyncHandler.h index 5cc1434d3..3d6203ad3 100644 --- a/CefSharp.BrowserSubprocess.Core/BindObjectAsyncHandler.h +++ b/CefSharp.BrowserSubprocess.Core/BindObjectAsyncHandler.h @@ -82,7 +82,7 @@ namespace CefSharp auto global = context->GetGlobal(); //Loop through all arguments and ignore anything that's not a string - for (auto i = 0; i < arguments.size(); i++) + for (size_t i = 0; i < arguments.size(); i++) { //Validate arg as being a string if (arguments[i]->IsString()) diff --git a/CefSharp.BrowserSubprocess.Core/Serialization/JsObjectsSerialization.cpp b/CefSharp.BrowserSubprocess.Core/Serialization/JsObjectsSerialization.cpp index 25e227287..27b237ae8 100644 --- a/CefSharp.BrowserSubprocess.Core/Serialization/JsObjectsSerialization.cpp +++ b/CefSharp.BrowserSubprocess.Core/Serialization/JsObjectsSerialization.cpp @@ -68,7 +68,7 @@ namespace CefSharp { auto result = gcnew List(); auto subList = list->GetList(index); - for (auto i = 0; i < subList->GetSize(); i++) + for (size_t i = 0; i < subList->GetSize(); i++) { result->Add(DeserializeJsObject(subList, i)); } @@ -77,4 +77,4 @@ namespace CefSharp } } } -} \ No newline at end of file +} diff --git a/CefSharp.BrowserSubprocess.Core/Serialization/V8Serialization.cpp b/CefSharp.BrowserSubprocess.Core/Serialization/V8Serialization.cpp index c335eb621..a47b1286b 100644 --- a/CefSharp.BrowserSubprocess.Core/Serialization/V8Serialization.cpp +++ b/CefSharp.BrowserSubprocess.Core/Serialization/V8Serialization.cpp @@ -83,7 +83,7 @@ namespace CefSharp if (obj->GetKeys(keys) && keys.size() > 0) { auto result = CefDictionaryValue::Create(); - for (int i = 0; i < keys.size(); i++) + for (size_t i = 0; i < keys.size(); i++) { auto p_keyStr = StringUtils::ToClr(keys[i].ToString()); if ((obj->HasValue(keys[i])) && (!p_keyStr->StartsWith("__"))) @@ -148,9 +148,9 @@ namespace CefSharp if (type == VTYPE_LIST) { auto subList = list->GetList(index); - auto size = subList->GetSize(); + size_t size = subList->GetSize(); auto result = CefV8Value::CreateArray(size); - for (auto i = 0; i < size; i++) + for (size_t i = 0; i < size; i++) { result->SetValue(i, DeserializeV8Object(subList, i)); } @@ -165,7 +165,7 @@ namespace CefSharp std::vector keys; subDict->GetKeys(keys); auto result = CefV8Value::CreateObject(nullptr, nullptr); - for (auto i = 0; i < size; i++) + for (size_t i = 0; i < size; i++) { result->SetValue(keys[i], DeserializeV8Object(subDict, keys[i]), V8_PROPERTY_ATTRIBUTE_NONE); } @@ -177,8 +177,9 @@ namespace CefSharp } template void SerializeV8Object(const CefRefPtr &value, const CefRefPtr& list, const int& index, JavascriptCallbackRegistry^ callbackRegistry); + template void SerializeV8Object(const CefRefPtr &value, const CefRefPtr& list, const size_t& index, JavascriptCallbackRegistry^ callbackRegistry); template void SerializeV8Object(const CefRefPtr &value, const CefRefPtr& list, const CefString& index, JavascriptCallbackRegistry^ callbackRegistry); - template void SerializeV8Object(const CefRefPtr &value, const CefRefPtr& list, const int& index, JavascriptCallbackRegistry^ callbackRegistry, value_deque &visited); + template void SerializeV8Object(const CefRefPtr &value, const CefRefPtr& list, const size_t& index, JavascriptCallbackRegistry^ callbackRegistry, value_deque &visited); template void SerializeV8Object(const CefRefPtr &value, const CefRefPtr& list, const CefString& index, JavascriptCallbackRegistry^ callbackRegistry, value_deque &visited); template CefRefPtr DeserializeV8Object(const CefRefPtr& list, const int& index); template CefRefPtr DeserializeV8Object(const CefRefPtr& list, const CefString& index); diff --git a/CefSharp.Core/Internals/CefExtensionWrapper.cpp b/CefSharp.Core/Internals/CefExtensionWrapper.cpp index 22c900982..e42e52a52 100644 --- a/CefSharp.Core/Internals/CefExtensionWrapper.cpp +++ b/CefSharp.Core/Internals/CefExtensionWrapper.cpp @@ -42,7 +42,7 @@ namespace CefSharp CefDictionaryValue::KeyList keys; dictionary->GetKeys(keys); - for (auto i = 0; i < keys.size(); i++) + for (size_t i = 0; i < keys.size(); i++) { auto key = keys[i]; auto keyValue = StringUtils::ToClr(key); diff --git a/CefSharp.Core/Internals/CefValueWrapper.cpp b/CefSharp.Core/Internals/CefValueWrapper.cpp index 32a4647e6..a369893c3 100644 --- a/CefSharp.Core/Internals/CefValueWrapper.cpp +++ b/CefSharp.Core/Internals/CefValueWrapper.cpp @@ -51,7 +51,7 @@ IDictionary^ CefValueWrapper::GetDictionary() CefDictionaryValue::KeyList keys; dictionary->GetKeys(keys); - for (auto i = 0; i < keys.size(); i++) + for (size_t i = 0; i < keys.size(); i++) { auto key = keys[i]; auto keyValue = StringUtils::ToClr(key); @@ -70,7 +70,7 @@ IList^ CefValueWrapper::GetList() auto list = _cefValue->GetList(); auto result = gcnew List(list->GetSize()); - for (auto i = 0; i < list->GetSize(); i++) + for (size_t i = 0; i < list->GetSize(); i++) { result->Add(gcnew CefValueWrapper(list->GetValue(i))); } @@ -83,4 +83,4 @@ Object^ CefValueWrapper::GetObject() ThrowIfDisposed(); return TypeConversion::FromNative(_cefValue.get()); -} \ No newline at end of file +} diff --git a/CefSharp.Core/Internals/ClientAdapter.cpp b/CefSharp.Core/Internals/ClientAdapter.cpp index 29654e760..24b186775 100644 --- a/CefSharp.Core/Internals/ClientAdapter.cpp +++ b/CefSharp.Core/Internals/ClientAdapter.cpp @@ -1086,7 +1086,7 @@ namespace CefSharp auto objectNames = argList->GetList(1); auto names = gcnew List(objectNames->GetSize()); - for (auto i = 0; i < objectNames->GetSize(); i++) + for (size_t i = 0; i < objectNames->GetSize(); i++) { names->Add(StringUtils::ToClr(objectNames->GetString(i))); } @@ -1113,7 +1113,7 @@ namespace CefSharp auto boundObjects = argList->GetList(0); auto objs = gcnew List^>(boundObjects->GetSize()); - for (auto i = 0; i < boundObjects->GetSize(); i++) + for (size_t i = 0; i < boundObjects->GetSize(); i++) { auto obj = boundObjects->GetDictionary(i); auto objectName = obj->GetString("Name"); diff --git a/CefSharp.Core/Internals/Serialization/ObjectsSerialization.cpp b/CefSharp.Core/Internals/Serialization/ObjectsSerialization.cpp index 650d6beca..a537a6650 100644 --- a/CefSharp.Core/Internals/Serialization/ObjectsSerialization.cpp +++ b/CefSharp.Core/Internals/Serialization/ObjectsSerialization.cpp @@ -55,7 +55,7 @@ namespace CefSharp { auto subList = list->GetList(index); auto array = gcnew List(subList->GetSize()); - for (auto i = 0; i < subList->GetSize(); i++) + for (size_t i = 0; i < subList->GetSize(); i++) { array->Add(DeserializeObject(subList, i, javascriptCallbackFactory)); } @@ -69,7 +69,7 @@ namespace CefSharp std::vector keys; subDict->GetKeys(keys); - for (auto i = 0; i < keys.size(); i++) + for (size_t i = 0; i < keys.size(); i++) { auto key = StringUtils::ToClr(keys[i]); auto value = DeserializeObject(subDict, keys[i], javascriptCallbackFactory); @@ -93,4 +93,4 @@ namespace CefSharp } } } -} \ No newline at end of file +} diff --git a/CefSharp.Core/Internals/Serialization/Primitives.h b/CefSharp.Core/Internals/Serialization/Primitives.h index 80156a2c3..6d4a3bbc0 100644 --- a/CefSharp.Core/Internals/Serialization/Primitives.h +++ b/CefSharp.Core/Internals/Serialization/Primitives.h @@ -34,24 +34,33 @@ namespace CefSharp bool IsJsCallback(const CefRefPtr& list, TIndex index); template void SetInt64(const CefRefPtr& list, int index, const int64 &value); + template void SetInt64(const CefRefPtr& list, size_t index, const int64 &value); template void SetInt64(const CefRefPtr& list, CefString index, const int64 &value); template int64 GetInt64(const CefRefPtr& list, int index); + template int64 GetInt64(const CefRefPtr& list, size_t index); template int64 GetInt64(const CefRefPtr& list, CefString index); template bool IsInt64(const CefRefPtr& list, int index); + template bool IsInt64(const CefRefPtr& list, size_t index); template bool IsInt64(const CefRefPtr& list, CefString index); template void SetCefTime(const CefRefPtr& list, int index, const CefTime &value); + template void SetCefTime(const CefRefPtr& list, size_t index, const CefTime &value); template void SetCefTime(const CefRefPtr& list, CefString index, const CefTime &value); template CefTime GetCefTime(const CefRefPtr& list, int index); + template CefTime GetCefTime(const CefRefPtr& list, size_t index); template CefTime GetCefTime(const CefRefPtr& list, CefString index); + template bool IsCefTime(const CefRefPtr& list, size_t index); template bool IsCefTime(const CefRefPtr& list, int index); template bool IsCefTime(const CefRefPtr& list, CefString index); template void SetJsCallback(const CefRefPtr& list, int index, JavascriptCallback^ value); + template void SetJsCallback(const CefRefPtr& list, size_t index, JavascriptCallback^ value); template void SetJsCallback(const CefRefPtr& list, CefString index, JavascriptCallback^ value); template JavascriptCallback^ GetJsCallback(const CefRefPtr& list, int index); + template JavascriptCallback^ GetJsCallback(const CefRefPtr& list, size_t index); template JavascriptCallback^ GetJsCallback(const CefRefPtr& list, CefString index); template bool IsJsCallback(const CefRefPtr& list, int index); + template bool IsJsCallback(const CefRefPtr& list, size_t index); template bool IsJsCallback(const CefRefPtr& list, CefString index); } } diff --git a/CefSharp.Core/Internals/Serialization/V8Serialization.h b/CefSharp.Core/Internals/Serialization/V8Serialization.h index 4ad01dc8f..528f9f475 100644 --- a/CefSharp.Core/Internals/Serialization/V8Serialization.h +++ b/CefSharp.Core/Internals/Serialization/V8Serialization.h @@ -22,6 +22,7 @@ namespace CefSharp void SerializeV8SimpleObject(const CefRefPtr& list, const TIndex& index, Object^ obj, HashSet^ seen, IJavascriptNameConverter^ nameConverter); template void SerializeV8Object(const CefRefPtr& list, const int& index, Object^ obj, IJavascriptNameConverter^ nameConverter); + template void SerializeV8Object(const CefRefPtr& list, const size_t& index, Object^ obj, IJavascriptNameConverter^ nameConverter); template void SerializeV8Object(const CefRefPtr& list, const CefString& index, Object^ obj, IJavascriptNameConverter^ nameConverter); } } diff --git a/CefSharp.Core/Internals/TypeConversion.h b/CefSharp.Core/Internals/TypeConversion.h index 169ad45fa..c61596063 100644 --- a/CefSharp.Core/Internals/TypeConversion.h +++ b/CefSharp.Core/Internals/TypeConversion.h @@ -241,7 +241,7 @@ namespace CefSharp CefDictionaryValue::KeyList keys; dictionary->GetKeys(keys); - for (auto i = 0; i < keys.size(); i++) + for (size_t i = 0; i < keys.size(); i++) { auto key = StringUtils::ToClr(keys[i]); auto value = DeserializeObject(dictionary, keys[i], nullptr); @@ -255,7 +255,7 @@ namespace CefSharp static List^ FromNative(const CefRefPtr& list) { auto result = gcnew List(list->GetSize()); - for (auto i = 0; i < list->GetSize(); i++) + for (size_t i = 0; i < list->GetSize(); i++) { result->Add(DeserializeObject(list, i, nullptr)); }