aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/cpp/cpp_message.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.cc
parent9c0b35cf620c4904a18e25733f50c9c0474fefa6 (diff)
Fix more implicit type conversions in public headers and generated code.
Diffstat (limited to 'src/google/protobuf/compiler/cpp/cpp_message.cc')
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_message.cc14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/google/protobuf/compiler/cpp/cpp_message.cc b/src/google/protobuf/compiler/cpp/cpp_message.cc
index d9524f64..1ab87638 100644
--- a/src/google/protobuf/compiler/cpp/cpp_message.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_message.cc
@@ -2308,12 +2308,13 @@ void MessageGenerator::GenerateConstructorBody(io::Printer* printer,
if (copy_constructor) {
pod_template =
"::memcpy(&$first$_, &from.$first$_,\n"
- " reinterpret_cast<char*>(&$last$_) -\n"
- " reinterpret_cast<char*>(&$first$_) + sizeof($last$_));\n";
+ " static_cast<size_t>(reinterpret_cast<char*>(&$last$_) -\n"
+ " reinterpret_cast<char*>(&$first$_)) + sizeof($last$_));\n";
} else {
pod_template =
- "::memset(&$first$_, 0, reinterpret_cast<char*>(&$last$_) -\n"
- " reinterpret_cast<char*>(&$first$_) + sizeof($last$_));\n";
+ "::memset(&$first$_, 0, static_cast<size_t>(\n"
+ " reinterpret_cast<char*>(&$last$_) -\n"
+ " reinterpret_cast<char*>(&$first$_)) + sizeof($last$_));\n";
}
for (int i = 0; i < optimized_order_.size(); ++i) {
@@ -2750,8 +2751,9 @@ GenerateClear(io::Printer* printer) {
FieldName(optimized_order_[memset_run_end]);
printer->Print(
- "::memset(&$first$_, 0, reinterpret_cast<char*>(&$last$_) -\n"
- " reinterpret_cast<char*>(&$first$_) + sizeof($last$_));\n",
+ "::memset(&$first$_, 0, static_cast<size_t>(\n"
+ " reinterpret_cast<char*>(&$last$_) -\n"
+ " reinterpret_cast<char*>(&$first$_)) + sizeof($last$_));\n",
"first", first_field_name,
"last", last_field_name);
}