From afa997d343b52365665705b80f6878b85a90044d Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Mon, 8 May 2023 16:01:08 -0700 Subject: [PATCH] Fix crash in #12104 This crash was due to the fact that we were passing `nullptr` as a `const char*` parameter and relying on that implicitly converting into an empty `absl::string_view`. `absl::string_view` supports that functionality, but starting with C++17 its behavior changes since it's just a type alias for `std::string_view`. `std::string_view` does not have any special conversion for nullptr and so we were just getting crashes. PiperOrigin-RevId: 530431663 --- src/google/protobuf/wire_format.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/google/protobuf/wire_format.h b/src/google/protobuf/wire_format.h index dec6774a3252..b1b42a9d9a60 100644 --- a/src/google/protobuf/wire_format.h +++ b/src/google/protobuf/wire_format.h @@ -357,8 +357,9 @@ inline size_t WireFormat::TagSize(int field_number, inline void WireFormat::VerifyUTF8String(const char* data, int size, WireFormat::Operation op) { #ifdef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED - WireFormatLite::VerifyUtf8String( - data, size, static_cast(op), nullptr); + WireFormatLite::VerifyUtf8String(data, size, + static_cast(op), + /* field_name = */ ""); #else // Avoid the compiler warning about unused variables. (void)data;