From 15a15e336b0295abaf3e06adc9c32807455a8368 Mon Sep 17 00:00:00 2001 From: Julien Brianceau Date: Tue, 20 Dec 2016 23:01:06 +0100 Subject: [PATCH] Init index_in_metadata_ without condition Chromium MemorySanitizer (MSan) reports use-of-uninitialized-value of index_in_metadata_ attribute from EnumGenerator class. Fix these warnings by initializing these attributes without condition. --- src/google/protobuf/compiler/cpp/cpp_file.cc | 21 +++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/google/protobuf/compiler/cpp/cpp_file.cc b/src/google/protobuf/compiler/cpp/cpp_file.cc index d8fda59c3..9cfd6ec6b 100644 --- a/src/google/protobuf/compiler/cpp/cpp_file.cc +++ b/src/google/protobuf/compiler/cpp/cpp_file.cc @@ -289,6 +289,18 @@ void FileGenerator::GenerateSource(io::Printer* printer) { "classname", message_generators_[i]->classname_); } + for (int i = 0; i < message_generators_.size(); i++) { + message_generators_[i]->index_in_metadata_ = i; + } + for (int i = 0; i < enum_generators_.size(); i++) { + enum_generators_[i]->index_in_metadata_ = i; + } + if (HasGenericServices(file_, options_)) { + for (int i = 0; i < service_generators_.size(); i++) { + service_generators_[i]->index_in_metadata_ = i; + } + } + if (HasDescriptorMethods(file_, options_)) { printer->Print( "\n" @@ -313,17 +325,8 @@ void FileGenerator::GenerateSource(io::Printer* printer) { } for (int i = 0; i < message_generators_.size(); i++) { - message_generators_[i]->index_in_metadata_ = i; message_generators_[i]->GenerateDescriptorDeclarations(printer); } - for (int i = 0; i < enum_generators_.size(); i++) { - enum_generators_[i]->index_in_metadata_ = i; - } - if (HasGenericServices(file_, options_)) { - for (int i = 0; i < service_generators_.size(); i++) { - service_generators_[i]->index_in_metadata_ = i; - } - } printer->Print( "\n"