From e31ce24d9a1158ffa97f145fe775daf3a70014b4 Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Fri, 6 Mar 2026 22:48:25 +0000 Subject: [PATCH] Fix clang-tidy warnings: cppcoreguidelines-init-variables --- api/include/opentelemetry/baggage/baggage.h | 2 +- .../opentelemetry/trace/propagation/http_trace_context.h | 4 ++-- api/include/opentelemetry/trace/propagation/jaeger.h | 2 +- api/include/opentelemetry/trace/trace_state.h | 2 +- sdk/include/opentelemetry/sdk/metrics/view/view_registry.h | 2 +- sdk/test/configuration/yaml_distribution_test.cc | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/api/include/opentelemetry/baggage/baggage.h b/api/include/opentelemetry/baggage/baggage.h index e3e08ff225..6e2354366c 100644 --- a/api/include/opentelemetry/baggage/baggage.h +++ b/api/include/opentelemetry/baggage/baggage.h @@ -121,7 +121,7 @@ class OPENTELEMETRY_EXPORT Baggage } nostd::shared_ptr baggage(new Baggage(cnt)); - bool kv_valid; + bool kv_valid{false}; nostd::string_view key, value; while (kv_str_tokenizer.next(kv_valid, key, value) && baggage->kv_properties_->Size() < cnt) diff --git a/api/include/opentelemetry/trace/propagation/http_trace_context.h b/api/include/opentelemetry/trace/propagation/http_trace_context.h index 81d4c308ec..76b94284ef 100644 --- a/api/include/opentelemetry/trace/propagation/http_trace_context.h +++ b/api/include/opentelemetry/trace/propagation/http_trace_context.h @@ -80,7 +80,7 @@ class HttpTraceContext : public context::propagation::TextMapPropagator static TraceFlags TraceFlagsFromHex(nostd::string_view trace_flags) { - uint8_t flags; + uint8_t flags{0}; detail::HexToBinary(trace_flags, &flags, sizeof(flags)); return TraceFlags(flags); } @@ -140,7 +140,7 @@ class HttpTraceContext : public context::propagation::TextMapPropagator } // hex is valid, convert it to binary - uint8_t version_binary; + uint8_t version_binary{kInvalidVersion}; detail::HexToBinary(version_hex, &version_binary, sizeof(version_binary)); if (version_binary == kInvalidVersion) { diff --git a/api/include/opentelemetry/trace/propagation/jaeger.h b/api/include/opentelemetry/trace/propagation/jaeger.h index 45a9370919..ac843f97b6 100644 --- a/api/include/opentelemetry/trace/propagation/jaeger.h +++ b/api/include/opentelemetry/trace/propagation/jaeger.h @@ -112,7 +112,7 @@ class JaegerPropagator : public context::propagation::TextMapPropagator return SpanContext::GetInvalid(); } - uint8_t flags; + uint8_t flags{0}; if (!detail::HexToBinary(flags_hex, &flags, sizeof(flags))) { return SpanContext::GetInvalid(); diff --git a/api/include/opentelemetry/trace/trace_state.h b/api/include/opentelemetry/trace/trace_state.h index df7a0e0fe9..7ed83284cb 100644 --- a/api/include/opentelemetry/trace/trace_state.h +++ b/api/include/opentelemetry/trace/trace_state.h @@ -64,7 +64,7 @@ class OPENTELEMETRY_EXPORT TraceState } nostd::shared_ptr ts(new TraceState(cnt)); - bool kv_valid; + bool kv_valid{false}; nostd::string_view key, value; while (kv_str_tokenizer.next(kv_valid, key, value) && ts->kv_properties_->Size() < cnt) { diff --git a/sdk/include/opentelemetry/sdk/metrics/view/view_registry.h b/sdk/include/opentelemetry/sdk/metrics/view/view_registry.h index e4d25ec3e7..4cc8711323 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/view_registry.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/view_registry.h @@ -68,7 +68,7 @@ class ViewRegistry if (aggregation_type == AggregationType::kDefault) { - bool is_monotonic; + bool is_monotonic{false}; aggregation_type = DefaultAggregation::GetDefaultAggregationType( instrument_selector->GetInstrumentType(), is_monotonic); } diff --git a/sdk/test/configuration/yaml_distribution_test.cc b/sdk/test/configuration/yaml_distribution_test.cc index 4b1e7ebf86..9ba73c43dc 100644 --- a/sdk/test/configuration/yaml_distribution_test.cc +++ b/sdk/test/configuration/yaml_distribution_test.cc @@ -67,7 +67,7 @@ file_format: "1.0-distribution" auto *distribution = config->distribution.get(); ASSERT_NE(distribution, nullptr); ASSERT_EQ(distribution->entries.size(), 2); - opentelemetry::sdk::configuration::DocumentNode *node; + opentelemetry::sdk::configuration::DocumentNode *node{nullptr}; std::unique_ptr property; std::string name;