Skip to content

Commit e2b4024

Browse files
fix C++ compiler warnings (#385)
* fix compiler warnings about conversions from size_t to int or UINT * change type of current_index from (signed) int to size_t * change another size_t * change some casts * use const reference
1 parent d8d6617 commit e2b4024

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

src/Datadog.Trace.ClrProfiler.Native/clr_helpers.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,13 @@ FunctionInfo GetFunctionInfo(const ComPtr<IMetaDataImport2>& metadata_import,
139139
if (FAILED(hr)) {
140140
return {};
141141
}
142-
auto generic_info = GetFunctionInfo(metadata_import, parent_token);
142+
const auto generic_info = GetFunctionInfo(metadata_import, parent_token);
143143
final_signature_bytes = generic_info.signature.data;
144144
method_spec_signature =
145145
GetSignatureByteRepresentation(raw_signature_len, raw_signature);
146146
std::memcpy(function_name, generic_info.name.c_str(),
147147
sizeof(WCHAR) * (generic_info.name.length() + 1));
148-
function_name_len = (DWORD)(generic_info.name.length() + 1);
148+
function_name_len = DWORD(generic_info.name.length() + 1);
149149
} break;
150150
default:
151151
Warn("[trace::GetFunctionInfo] unknown token type: {}", token_type);
@@ -255,7 +255,7 @@ mdAssemblyRef FindAssemblyRef(
255255

256256
std::vector<Integration> FilterIntegrationsByName(
257257
const std::vector<Integration>& integrations,
258-
const std::vector<WSTRING> integration_names) {
258+
const std::vector<WSTRING>& integration_names) {
259259
std::vector<Integration> enabled;
260260

261261
for (auto& i : integrations) {
@@ -391,7 +391,7 @@ bool DisableOptimizations() {
391391

392392
TypeInfo RetrieveTypeForSignature(
393393
const ComPtr<IMetaDataImport2>& metadata_import,
394-
const FunctionInfo& function_info, const int& current_index,
394+
const FunctionInfo& function_info, const size_t current_index,
395395
ULONG& token_length) {
396396
mdToken type_token;
397397
const auto type_token_start =
@@ -404,23 +404,23 @@ TypeInfo RetrieveTypeForSignature(
404404
bool SignatureFuzzyMatch(const ComPtr<IMetaDataImport2>& metadata_import,
405405
const FunctionInfo& function_info,
406406
std::vector<WSTRING>& signature_result) {
407-
const int signature_size = function_info.signature.data.size();
408-
auto generic_count = function_info.signature.NumberOfTypeArguments();
409-
auto param_count = function_info.signature.NumberOfArguments();
410-
auto current_index = 2; // Where the parameters actually start
407+
const auto signature_size = function_info.signature.data.size();
408+
const auto generic_count = function_info.signature.NumberOfTypeArguments();
409+
const auto param_count = function_info.signature.NumberOfArguments();
410+
size_t current_index = 2; // Where the parameters actually start
411411

412412
if (generic_count > 0) {
413413
current_index++; // offset by one because the method is generic
414414
}
415415

416-
const UINT expected_number_of_types = param_count + 1;
417-
UINT current_type_index = 0;
416+
const auto expected_number_of_types = param_count + 1;
417+
size_t current_type_index = 0;
418418
std::vector<WSTRING> type_names(expected_number_of_types);
419419

420420
std::stack<int> generic_arg_stack;
421421
WSTRING append_to_type = ""_W;
422422
WSTRING current_type_name = ""_W;
423-
423+
424424
for (; current_index < signature_size; current_index++) {
425425
mdToken type_token;
426426
ULONG token_length;
@@ -517,9 +517,8 @@ bool SignatureFuzzyMatch(const ComPtr<IMetaDataImport2>& metadata_import,
517517

518518
case ELEMENT_TYPE_SZARRAY: {
519519
append_to_type.append("[]"_W);
520-
while (
521-
CorElementType(function_info.signature.data[current_index + 1]) ==
522-
ELEMENT_TYPE_SZARRAY) {
520+
while (function_info.signature.data[(current_index + 1)] ==
521+
ELEMENT_TYPE_SZARRAY) {
523522
append_to_type.append("[]"_W);
524523
current_index++;
525524
}

src/Datadog.Trace.ClrProfiler.Native/clr_helpers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ mdAssemblyRef FindAssemblyRef(
284284
// disabled_integration_names
285285
std::vector<Integration> FilterIntegrationsByName(
286286
const std::vector<Integration>& integrations,
287-
std::vector<WSTRING> integration_names);
287+
const std::vector<WSTRING>& integration_names);
288288

289289
// FlattenIntegrations flattens integrations to per method structures
290290
std::vector<IntegrationMethod> FlattenIntegrations(

0 commit comments

Comments
 (0)