Skip to content

Commit 69fdf67

Browse files
authored
Improvement: span_id should not break strict aliasing. (#1068)
1 parent 9772156 commit 69fdf67

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

api/include/opentelemetry/trace/span_id.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ class SpanId final
6060
// Returns false if the SpanId is all zeros.
6161
bool IsValid() const noexcept
6262
{
63-
static_assert(kSize == 8, "update is needed if kSize is not 8");
64-
return *reinterpret_cast<const uint64_t *>(&rep_) != 0ull;
63+
static constexpr uint8_t kEmptyRep[kSize] = {0};
64+
return memcmp(rep_, kEmptyRep, kSize) != 0;
6565
}
6666

6767
// Copies the opaque SpanId data to dest.

0 commit comments

Comments
 (0)