From 69fdf6715461d892414392586af14fd1917dff82 Mon Sep 17 00:00:00 2001 From: Shuai Zhang Date: Tue, 16 Nov 2021 14:44:54 +0800 Subject: [PATCH] Improvement: span_id should not break strict aliasing. (#1068) --- api/include/opentelemetry/trace/span_id.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/include/opentelemetry/trace/span_id.h b/api/include/opentelemetry/trace/span_id.h index e282a2021a..63d2f36894 100644 --- a/api/include/opentelemetry/trace/span_id.h +++ b/api/include/opentelemetry/trace/span_id.h @@ -60,8 +60,8 @@ class SpanId final // Returns false if the SpanId is all zeros. bool IsValid() const noexcept { - static_assert(kSize == 8, "update is needed if kSize is not 8"); - return *reinterpret_cast(&rep_) != 0ull; + static constexpr uint8_t kEmptyRep[kSize] = {0}; + return memcmp(rep_, kEmptyRep, kSize) != 0; } // Copies the opaque SpanId data to dest.