diff options
Diffstat (limited to 'src/google/protobuf/wire_format_lite.cc')
-rw-r--r-- | src/google/protobuf/wire_format_lite.cc | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/src/google/protobuf/wire_format_lite.cc b/src/google/protobuf/wire_format_lite.cc index 1d8cda5a..a393f367 100644 --- a/src/google/protobuf/wire_format_lite.cc +++ b/src/google/protobuf/wire_format_lite.cc @@ -43,6 +43,7 @@ #include <google/protobuf/io/coded_stream_inl.h> #include <google/protobuf/io/zero_copy_stream.h> #include <google/protobuf/io/zero_copy_stream_impl_lite.h> +#include <google/protobuf/port_def.inc> namespace google { @@ -301,8 +302,7 @@ bool WireFormatLite::ReadPackedEnumNoInline(io::CodedInputStream* input, io::CodedInputStream::Limit limit = input->PushLimit(length); while (input->BytesUntilLimit() > 0) { int value; - if (!google::protobuf::internal::WireFormatLite::ReadPrimitive< - int, WireFormatLite::TYPE_ENUM>(input, &value)) { + if (!ReadPrimitive<int, WireFormatLite::TYPE_ENUM>(input, &value)) { return false; } if (is_valid == NULL || is_valid(value)) { @@ -324,8 +324,7 @@ bool WireFormatLite::ReadPackedEnumPreserveUnknowns( io::CodedInputStream::Limit limit = input->PushLimit(length); while (input->BytesUntilLimit() > 0) { int value; - if (!google::protobuf::internal::WireFormatLite::ReadPrimitive< - int, WireFormatLite::TYPE_ENUM>(input, &value)) { + if (!ReadPrimitive<int, WireFormatLite::TYPE_ENUM>(input, &value)) { return false; } if (is_valid == NULL || is_valid(value)) { @@ -583,7 +582,7 @@ void WireFormatLite::WriteMessageMaybeToArray(int field_number, } } -GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE static bool ReadBytesToString( +PROTOBUF_ALWAYS_INLINE static bool ReadBytesToString( io::CodedInputStream* input, string* value); inline static bool ReadBytesToString(io::CodedInputStream* input, string* value) { @@ -597,12 +596,25 @@ bool WireFormatLite::ReadBytes(io::CodedInputStream* input, string* value) { } bool WireFormatLite::ReadBytes(io::CodedInputStream* input, string** p) { - if (*p == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) { + if (*p == &GetEmptyStringAlreadyInited()) { *p = new ::std::string(); } return ReadBytesToString(input, *p); } +void PrintUTF8ErrorLog(const char* field_name, const char* operation_str, + bool emit_stacktrace) { + string stacktrace; + string quoted_field_name = ""; + if (field_name != nullptr) { + quoted_field_name = StringPrintf(" '%s'", field_name); + } + GOOGLE_LOG(ERROR) << "String field" << quoted_field_name << " contains invalid " + << "UTF-8 data when " << operation_str << " a protocol " + << "buffer. Use the 'bytes' type if you intend to send raw " + << "bytes. " << stacktrace; +} + bool WireFormatLite::VerifyUtf8String(const char* data, int size, Operation op, @@ -618,15 +630,7 @@ bool WireFormatLite::VerifyUtf8String(const char* data, break; // no default case: have the compiler warn if a case is not covered. } - string quoted_field_name = ""; - if (field_name != NULL) { - quoted_field_name = StringPrintf(" '%s'", field_name); - } - // no space below to avoid double space when the field name is missing. - GOOGLE_LOG(ERROR) << "String field" << quoted_field_name << " contains invalid " - << "UTF-8 data when " << operation_str << " a protocol " - << "buffer. Use the 'bytes' type if you intend to send raw " - << "bytes. "; + PrintUTF8ErrorLog(field_name, operation_str, false); return false; } return true; |