aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/cpp/cpp_message_field.cc
diff options
context:
space:
mode:
authorGravatar Bo Yang <teboring@google.com>2017-06-23 12:56:44 -0700
committerGravatar Bo Yang <paulyang1211@gmail.com>2017-06-24 11:28:13 -0700
commite3c807d4e752b477b707f5d021264faf9b127304 (patch)
tree505092dff769b14d6a07be62314bc948b9398090 /src/google/protobuf/compiler/cpp/cpp_message_field.cc
parent9c0b35cf620c4904a18e25733f50c9c0474fefa6 (diff)
Fix more implicit type conversions in public headers and generated code.
Diffstat (limited to 'src/google/protobuf/compiler/cpp/cpp_message_field.cc')
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_message_field.cc14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/google/protobuf/compiler/cpp/cpp_message_field.cc b/src/google/protobuf/compiler/cpp/cpp_message_field.cc
index fc3c4564..ed1719cc 100644
--- a/src/google/protobuf/compiler/cpp/cpp_message_field.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_message_field.cc
@@ -1084,19 +1084,21 @@ GenerateMergeFromCodedStream(io::Printer* printer) const {
void RepeatedMessageFieldGenerator::
GenerateSerializeWithCachedSizes(io::Printer* printer) const {
printer->Print(variables_,
- "for (unsigned int i = 0, n = this->$name$_size(); i < n; i++) {\n"
+ "for (unsigned int i = 0,\n"
+ " n = static_cast<unsigned int>(this->$name$_size()); i < n; i++) {\n"
" ::google::protobuf::internal::WireFormatLite::Write$stream_writer$(\n"
- " $number$, this->$name$(i), output);\n"
+ " $number$, this->$name$(static_cast<int>(i)), output);\n"
"}\n");
}
void RepeatedMessageFieldGenerator::
GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const {
printer->Print(variables_,
- "for (unsigned int i = 0, n = this->$name$_size(); i < n; i++) {\n"
+ "for (unsigned int i = 0,\n"
+ " n = static_cast<unsigned int>(this->$name$_size()); i < n; i++) {\n"
" target = ::google::protobuf::internal::WireFormatLite::\n"
" InternalWrite$declared_type$NoVirtualToArray(\n"
- " $number$, this->$name$(i), deterministic, target);\n"
+ " $number$, this->$name$(static_cast<int>(i)), deterministic, target);\n"
"}\n");
}
@@ -1104,14 +1106,14 @@ void RepeatedMessageFieldGenerator::
GenerateByteSize(io::Printer* printer) const {
printer->Print(variables_,
"{\n"
- " unsigned int count = this->$name$_size();\n");
+ " unsigned int count = static_cast<unsigned int>(this->$name$_size());\n");
printer->Indent();
printer->Print(variables_,
"total_size += $tag_size$UL * count;\n"
"for (unsigned int i = 0; i < count; i++) {\n"
" total_size +=\n"
" ::google::protobuf::internal::WireFormatLite::$declared_type$SizeNoVirtual(\n"
- " this->$name$(i));\n"
+ " this->$name$(static_cast<int>(i)));\n"
"}\n");
printer->Outdent();
printer->Print("}\n");