From c80233a4baa85550f9e6aaf0f1e8c44e59ece66d Mon Sep 17 00:00:00 2001 From: Esun Kim Date: Mon, 20 Sep 2021 14:00:46 -0700 Subject: [PATCH] Fix bugs in error (#27377) --- src/core/lib/gprpp/status_helper.cc | 5 +++-- src/core/lib/iomgr/error.cc | 8 ++++---- src/core/lib/iomgr/error.h | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/core/lib/gprpp/status_helper.cc b/src/core/lib/gprpp/status_helper.cc index f13cd403fe7..849e5e2edf5 100644 --- a/src/core/lib/gprpp/status_helper.cc +++ b/src/core/lib/gprpp/status_helper.cc @@ -131,8 +131,9 @@ void EncodeUInt32ToBytes(uint32_t v, char* buf) { } uint32_t DecodeUInt32FromBytes(const char* buf) { - return buf[0] | (uint32_t(buf[1]) << 8) | (uint32_t(buf[2]) << 16) | - (uint32_t(buf[3]) << 24); + const unsigned char* ubuf = reinterpret_cast(buf); + return ubuf[0] | (uint32_t(ubuf[1]) << 8) | (uint32_t(ubuf[2]) << 16) | + (uint32_t(ubuf[3]) << 24); } std::vector ParseChildren(absl::Cord children) { diff --git a/src/core/lib/iomgr/error.cc b/src/core/lib/iomgr/error.cc index c47c7928dd9..b4967c32b87 100644 --- a/src/core/lib/iomgr/error.cc +++ b/src/core/lib/iomgr/error.cc @@ -65,7 +65,7 @@ absl::Status grpc_status_create(absl::StatusCode code, absl::string_view msg, return s; } -std::string grpc_error_std_string(const absl::Status& error) { +std::string grpc_error_std_string(absl::Status error) { return grpc_core::StatusToString(error); } @@ -87,9 +87,9 @@ absl::Status grpc_wsa_error(const grpc_core::DebugLocation& location, int err, char* utf8_message = gpr_format_message(err); absl::Status s = StatusCreate(absl::StatusCode::kUnknown, "WSA Error", location, {}); - StatusSetInt(&s, StatusIntProperty::WSA_ERROR, err); - StatusSetStr(&s, StatusStrProperty::OS_ERROR, utf8_message); - StatusSetStr(&s, StatusStrProperty::SYSCALL, call_name); + StatusSetInt(&s, grpc_core::StatusIntProperty::WSA_ERROR, err); + StatusSetStr(&s, grpc_core::StatusStrProperty::OS_ERROR, utf8_message); + StatusSetStr(&s, grpc_core::StatusStrProperty::SYSCALL, call_name); } #endif diff --git a/src/core/lib/iomgr/error.h b/src/core/lib/iomgr/error.h index cd68014571e..29645b9e97b 100644 --- a/src/core/lib/iomgr/error.h +++ b/src/core/lib/iomgr/error.h @@ -189,11 +189,11 @@ absl::Status grpc_status_create(absl::StatusCode code, absl::string_view msg, // them. If the vector is empty, return GRPC_ERROR_NONE. template static absl::Status grpc_status_create_from_vector( - const grpc_core::DebugLocation& location, const char* desc, + const grpc_core::DebugLocation& location, absl::string_view desc, VectorType* error_list) { absl::Status error = GRPC_ERROR_NONE; if (error_list->size() != 0) { - error = grpc_status_create(absl::StatusCode::kUnknown, desc, DEBUG_LOCATION, + error = grpc_status_create(absl::StatusCode::kUnknown, desc, location, error_list->size(), error_list->data()); error_list->clear(); }