Skip to content

Commit cf37152

Browse files
Fix various warnings on windows (#734)
Fix various warnings: * signed/unsigned compare * variable shadowing * assignment in conditional expression warning Small code refactoring. Relates-To: OLPEDGE-1728 Signed-off-by: Mykhailo Kuchma <[email protected]>
1 parent 0be2028 commit cf37152

File tree

8 files changed

+71
-83
lines changed

8 files changed

+71
-83
lines changed

olp-cpp-sdk-authentication/src/AuthenticationCredentials.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ const std::string kHereAccessKeySecret = "here.access.key.secret";
3333
std::string GetDefaultPath() {
3434
const char* env;
3535
#ifdef _WIN32
36-
if ((env = std::getenv("HOMEDRIVE"))) {
36+
if ((env = std::getenv("HOMEDRIVE")) != nullptr) {
3737
std::string path{env};
3838

39-
if ((env = std::getenv("HOMEPATH"))) {
39+
if ((env = std::getenv("HOMEPATH")) != nullptr) {
4040
path.append(env).append("\\.here\\credentials.properties");
4141
return path;
4242
}

olp-cpp-sdk-authentication/src/BaseResult.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ BaseResult::BaseResult(int status, std::string error,
7171
for (SizeType i = 0; i < fields.Size(); i++) {
7272
const Value& field = fields[i];
7373
if (field.HasMember(ERROR_MESSAGE)) {
74-
ErrorField error;
75-
error.name = field[FIELD_NAME].GetString();
76-
error.code = field[ERROR_CODE].GetUint();
77-
error.message = field[ERROR_MESSAGE].GetString();
78-
error_fields_.emplace_back(error);
74+
ErrorField error_field;
75+
error_field.name = field[FIELD_NAME].GetString();
76+
error_field.code = field[ERROR_CODE].GetUint();
77+
error_field.message = field[ERROR_MESSAGE].GetString();
78+
error_fields_.emplace_back(error_field);
7979
}
8080
}
8181
}

olp-cpp-sdk-core/include/olp/core/generated/serializer/SerializerWrapper.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ inline void to_json(bool x, rapidjson::Value& value,
5757
inline void to_json(const std::shared_ptr<std::vector<unsigned char>>& x,
5858
rapidjson::Value& value,
5959
rapidjson::Document::AllocatorType& allocator) {
60-
value.SetString(reinterpret_cast<char*>(x->data()), x->size(), allocator);
60+
value.SetString(reinterpret_cast<char*>(x->data()),
61+
static_cast<rapidjson::SizeType>(x->size()), allocator);
6162
}
6263

6364
template <typename T>

olp-cpp-sdk-core/src/http/winhttp/NetworkWinHttp.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ bool ConvertMultiByteToWideChar(const std::string& in, std::wstring& out) {
158158
const auto conversion_result =
159159
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, in.c_str(),
160160
-1, // denotes null-terminated string
161-
&out.front(), out.size());
161+
&out.front(), static_cast<int>(out.size()));
162162

163163
// Should not happen as 1st call have succeeded.
164164
return conversion_result != 0;
@@ -450,18 +450,20 @@ SendOutcome NetworkWinHttp::Send(NetworkRequest request,
450450

451451
if (username_res && password_res) {
452452
LPCWSTR proxy_lpcwstr_username = proxy_username.c_str();
453-
if (!WinHttpSetOption(http_request, WINHTTP_OPTION_PROXY_USERNAME,
454-
const_cast<LPWSTR>(proxy_lpcwstr_username),
455-
wcslen(proxy_lpcwstr_username))) {
453+
if (!WinHttpSetOption(
454+
http_request, WINHTTP_OPTION_PROXY_USERNAME,
455+
const_cast<LPWSTR>(proxy_lpcwstr_username),
456+
static_cast<DWORD>(wcslen(proxy_lpcwstr_username)))) {
456457
OLP_SDK_LOG_WARNING(
457458
kLogTag, "WinHttpSetOption(proxy username) failed, url="
458459
<< request.GetUrl() << ", error=" << GetLastError());
459460
}
460461

461462
LPCWSTR proxy_lpcwstr_password = proxy_password.c_str();
462-
if (!WinHttpSetOption(http_request, WINHTTP_OPTION_PROXY_PASSWORD,
463-
const_cast<LPWSTR>(proxy_lpcwstr_password),
464-
wcslen(proxy_lpcwstr_password))) {
463+
if (!WinHttpSetOption(
464+
http_request, WINHTTP_OPTION_PROXY_PASSWORD,
465+
const_cast<LPWSTR>(proxy_lpcwstr_password),
466+
static_cast<DWORD>(wcslen(proxy_lpcwstr_password)))) {
465467
OLP_SDK_LOG_WARNING(
466468
kLogTag, "WinHttpSetOption(proxy password) failed, url="
467469
<< request.GetUrl() << ", error=" << GetLastError());
@@ -604,7 +606,7 @@ void NetworkWinHttp::RequestCallback(HINTERNET, DWORD_PTR context, DWORD status,
604606
auto buffer = std::make_unique<char[]>(len);
605607
const int convertResult = WideCharToMultiByte(
606608
CP_ACP, 0, wide_buffer.get(), len, buffer.get(), len, 0, nullptr);
607-
assert(convertResult == len);
609+
assert(convertResult == static_cast<int>(len));
608610

609611
DWORD start = 0, index = 0;
610612
while (index < len) {

olp-cpp-sdk-dataservice-read/src/VersionedLayerClientImpl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,9 @@ CatalogVersionResponse VersionedLayerClientImpl::GetVersion(
421421

422422
if (!catalog_version_.compare_exchange_weak(
423423
version, response.GetResult().GetVersion())) {
424-
model::VersionResponse response;
425-
response.SetVersion(version);
426-
return response;
424+
model::VersionResponse version_response;
425+
version_response.SetVersion(version);
426+
return version_response;
427427
}
428428

429429
return response;

olp-cpp-sdk-dataservice-write/src/VolatileLayerClientImpl.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,8 +729,6 @@ olp::client::CancellationToken VolatileLayerClientImpl::PublishToBatch(
729729
*self->apiclient_publish_, std::move(publish_partitions),
730730
publication_id, first_layer_id, first_layer_billing_tag,
731731
upload_partitions_callback);
732-
733-
return {};
734732
};
735733

736734
cancel_context->ExecuteOrCancelled(

olp-cpp-sdk-dataservice-write/src/generated/serializer/IndexInfoSerializer.cpp

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,38 +28,29 @@ void to_json(const dataservice::write::model::Index &x, rapidjson::Value &value,
2828
jsonValue.AddMember("id", rapidjson::StringRef(x.GetId().c_str()), allocator);
2929

3030
rapidjson::Value indexFields(rapidjson::kObjectType);
31-
for (auto &field : x.GetIndexFields()) {
32-
auto value = field.second;
33-
const auto key = rapidjson::StringRef(field.first.c_str());
34-
if (value->getIndexType() == dataservice::write::model::IndexType::String) {
35-
auto s =
36-
std::static_pointer_cast<dataservice::write::model::StringIndexValue>(
37-
value);
31+
for (auto &field_pair : x.GetIndexFields()) {
32+
using namespace dataservice::write::model;
33+
const auto &field = field_pair.second;
34+
const auto key = rapidjson::StringRef(field_pair.first.c_str());
35+
auto index_type = field->getIndexType();
36+
if (index_type == IndexType::String) {
37+
auto s = std::static_pointer_cast<StringIndexValue>(field);
3838
rapidjson::Value str_val;
39-
str_val.SetString(s->GetValue().c_str(), (int)s->GetValue().size(),
40-
allocator);
39+
const auto &str = s->GetValue();
40+
str_val.SetString(
41+
str.c_str(), static_cast<rapidjson::SizeType>(str.size()), allocator);
4142
indexFields.AddMember(key, str_val, allocator);
42-
43-
} else if (value->getIndexType() ==
44-
dataservice::write::model::IndexType::Int) {
45-
auto s =
46-
std::static_pointer_cast<dataservice::write::model::IntIndexValue>(
47-
value);
43+
} else if (index_type == IndexType::Int) {
44+
auto s = std::static_pointer_cast<IntIndexValue>(field);
4845
indexFields.AddMember(key, s->GetValue(), allocator);
49-
} else if (value->getIndexType() ==
50-
dataservice::write::model::IndexType::Bool) {
51-
auto s = std::static_pointer_cast<
52-
dataservice::write::model::BooleanIndexValue>(value);
46+
} else if (index_type == IndexType::Bool) {
47+
auto s = std::static_pointer_cast<BooleanIndexValue>(field);
5348
indexFields.AddMember(key, s->GetValue(), allocator);
54-
} else if (value->getIndexType() ==
55-
dataservice::write::model::IndexType::Heretile) {
56-
auto s = std::static_pointer_cast<
57-
dataservice::write::model::HereTileIndexValue>(value);
49+
} else if (index_type == IndexType::Heretile) {
50+
auto s = std::static_pointer_cast<HereTileIndexValue>(field);
5851
indexFields.AddMember(key, s->GetValue(), allocator);
59-
} else if (value->getIndexType() ==
60-
dataservice::write::model::IndexType::TimeWindow) {
61-
auto s = std::static_pointer_cast<
62-
dataservice::write::model::TimeWindowIndexValue>(value);
52+
} else if (index_type == IndexType::TimeWindow) {
53+
auto s = std::static_pointer_cast<TimeWindowIndexValue>(field);
6354
indexFields.AddMember(key, s->GetValue(), allocator);
6455
}
6556
}
@@ -69,10 +60,12 @@ void to_json(const dataservice::write::model::Index &x, rapidjson::Value &value,
6960
if (x.GetMetadata()) {
7061
rapidjson::Value metadatas(rapidjson::kObjectType);
7162
for (auto metadata : x.GetMetadata().get()) {
72-
auto value = metadata.second;
73-
auto key = metadata.first.c_str();
74-
indexFields.AddMember(rapidjson::StringRef(key),
75-
rapidjson::StringRef(value.c_str()), allocator);
63+
auto metadata_value = metadata.second;
64+
auto metadata_key = metadata.first.c_str();
65+
indexFields.AddMember(
66+
rapidjson::StringRef(metadata_key),
67+
rapidjson::StringRef(metadata_value.c_str(), metadata_value.size()),
68+
allocator);
7669
}
7770
}
7871

olp-cpp-sdk-dataservice-write/src/generated/serializer/UpdateIndexRequestSerializer.cpp

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -31,38 +31,30 @@ void to_json(const dataservice::write::model::UpdateIndexRequest &x,
3131
"id", rapidjson::StringRef(addition.GetId().c_str()), allocator);
3232

3333
rapidjson::Value indexFields(rapidjson::kObjectType);
34-
for (auto &field : addition.GetIndexFields()) {
35-
auto value = field.second;
36-
const auto key = rapidjson::StringRef(field.first.c_str());
37-
if (value->getIndexType() ==
38-
dataservice::write::model::IndexType::String) {
39-
auto s = std::static_pointer_cast<
40-
dataservice::write::model::StringIndexValue>(value);
34+
for (const auto &field_pair : addition.GetIndexFields()) {
35+
using namespace dataservice::write::model;
36+
const auto &field = field_pair.second;
37+
const auto key = rapidjson::StringRef(field_pair.first.c_str());
38+
auto index_type = field->getIndexType();
39+
if (index_type == IndexType::String) {
40+
auto s = std::static_pointer_cast<StringIndexValue>(field);
4141
rapidjson::Value str_val;
42-
str_val.SetString(s->GetValue().c_str(), (int)s->GetValue().size(),
42+
const auto &str = s->GetValue();
43+
str_val.SetString(str.c_str(),
44+
static_cast<rapidjson::SizeType>(str.size()),
4345
allocator);
4446
indexFields.AddMember(key, str_val, allocator);
45-
46-
} else if (value->getIndexType() ==
47-
dataservice::write::model::IndexType::Int) {
48-
auto s =
49-
std::static_pointer_cast<dataservice::write::model::IntIndexValue>(
50-
value);
47+
} else if (index_type == IndexType::Int) {
48+
auto s = std::static_pointer_cast<IntIndexValue>(field);
5149
indexFields.AddMember(key, s->GetValue(), allocator);
52-
} else if (value->getIndexType() ==
53-
dataservice::write::model::IndexType::Bool) {
54-
auto s = std::static_pointer_cast<
55-
dataservice::write::model::BooleanIndexValue>(value);
50+
} else if (index_type == IndexType::Bool) {
51+
auto s = std::static_pointer_cast<BooleanIndexValue>(field);
5652
indexFields.AddMember(key, s->GetValue(), allocator);
57-
} else if (value->getIndexType() ==
58-
dataservice::write::model::IndexType::Heretile) {
59-
auto s = std::static_pointer_cast<
60-
dataservice::write::model::HereTileIndexValue>(value);
53+
} else if (index_type == IndexType::Heretile) {
54+
auto s = std::static_pointer_cast<HereTileIndexValue>(field);
6155
indexFields.AddMember(key, s->GetValue(), allocator);
62-
} else if (value->getIndexType() ==
63-
dataservice::write::model::IndexType::TimeWindow) {
64-
auto s = std::static_pointer_cast<
65-
dataservice::write::model::TimeWindowIndexValue>(value);
56+
} else if (index_type == IndexType::TimeWindow) {
57+
auto s = std::static_pointer_cast<TimeWindowIndexValue>(field);
6658
indexFields.AddMember(key, s->GetValue(), allocator);
6759
}
6860
}
@@ -71,11 +63,13 @@ void to_json(const dataservice::write::model::UpdateIndexRequest &x,
7163
// by another model.
7264
if (addition.GetMetadata()) {
7365
rapidjson::Value metadatas(rapidjson::kObjectType);
74-
for (auto metadata : addition.GetMetadata().get()) {
75-
auto value = metadata.second;
76-
auto key = metadata.first.c_str();
77-
indexFields.AddMember(rapidjson::StringRef(key),
78-
rapidjson::StringRef(value.c_str()), allocator);
66+
for (const auto& metadata : addition.GetMetadata().get()) {
67+
const auto& metadata_value = metadata.second;
68+
const auto& metadata_key = metadata.first.c_str();
69+
indexFields.AddMember(
70+
rapidjson::StringRef(metadata_key),
71+
rapidjson::StringRef(metadata_value.c_str(), metadata_value.size()),
72+
allocator);
7973
}
8074
}
8175

0 commit comments

Comments
 (0)