Skip to content

Commit cc4c09c

Browse files
committed
Improvement: span_id should not break strict aliasing.
1 parent 4a49b1b commit cc4c09c

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

api/include/opentelemetry/trace/span_id.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ class SpanId final
6161
bool IsValid() const noexcept
6262
{
6363
static_assert(kSize == 8, "update is needed if kSize is not 8");
64-
return *reinterpret_cast<const uint64_t *>(&rep_) != 0ull;
64+
static constexpr uint8_t kEmptyRep[kSize] = {0};
65+
return memcmp(rep_, kEmptyRep, kSize) != 0;
6566
}
6667

6768
// Copies the opaque SpanId data to dest.

0 commit comments

Comments
 (0)