Fix the unaligned access to Time of Status (#30033)

pull/29714/head
Esun Kim 3 years ago committed by GitHub
parent 48885b74b0
commit 323be889af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      src/core/lib/gprpp/status_helper.cc

@ -327,8 +327,10 @@ std::string StatusToString(const absl::Status& status) {
absl::CHexEscape(payload_view), "\""));
} else if (absl::StartsWith(type_url, kTypeTimeTag)) {
type_url.remove_prefix(kTypeTimeTag.size());
absl::Time t =
*reinterpret_cast<const absl::Time*>(payload_view.data());
// copy the content before casting to avoid misaligned address access
alignas(absl::Time) char buf[sizeof(const absl::Time)];
memcpy(buf, payload_view.data(), sizeof(const absl::Time));
absl::Time t = *reinterpret_cast<const absl::Time*>(buf);
kvs.push_back(absl::StrCat(type_url, ":\"", absl::FormatTime(t), "\""));
} else {
kvs.push_back(absl::StrCat(type_url, ":\"",

Loading…
Cancel
Save