Fix clang-tidy errors
- Moved built-in data type default values to be set at their definition
rather than in the constructor to fix modernize-use-default-member-init
warnings.
- Surround exception-throwing string functions in main functions in a
try-catch block to fix bugprone-exception-escape warnings.
- Adds `cmake-build-debug` folder to the lint exclusion list, to
prevent false failures due to header checks on local lint runs.
- Remove unused `using` declarations.
Bug: 95383
Change-Id: I8d5cb116e69e7a7dc21356edd701994c749d8c30
Reviewed-on: https://fuchsia-review.googlesource.com/c/cobalt/+/656650
Fuchsia-Auto-Submit: Steve Fung <stevefung@google.com>
Reviewed-by: Zach Bush <zmbush@google.com>
Commit-Queue: Auto-Submit <auto-submit@fuchsia-infra.iam.gserviceaccount.com>
diff --git a/keys/keys_tests.cc b/keys/keys_tests.cc
index ad4aea6..939e228 100644
--- a/keys/keys_tests.cc
+++ b/keys/keys_tests.cc
@@ -95,12 +95,17 @@
int main(int argc, char* argv[]) {
// Compute the path where keys are stored in the output directory.
- std::string path(argv[0]);
- auto slash = path.find_last_of('/');
- CHECK(slash != std::string::npos);
- path = path.substr(0, slash) + "/keys/";
- kKeysDir = path.c_str();
+ try {
+ std::string path(argv[0]);
+ auto slash = path.find_last_of('/');
+ CHECK(slash != std::string::npos);
+ path = path.substr(0, slash) + "/keys/";
+ kKeysDir = path.c_str();
- ::testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+ } catch (...) {
+ LOG(FATAL) << "Exception caught.";
+ return 1;
+ }
}
diff --git a/src/bin/test_app/test_app.cc b/src/bin/test_app/test_app.cc
index 3a0179c..eaa7bad 100644
--- a/src/bin/test_app/test_app.cc
+++ b/src/bin/test_app/test_app.cc
@@ -41,7 +41,6 @@
using logger::LoggerInterface;
using logger::ProjectContext;
using logger::ProjectContextFactory;
-using system_data::ClientSecret;
using util::FakeValidatedClock;
using util::IncrementingSystemClock;
using util::PosixFileSystem;
diff --git a/src/bin/test_app/test_app_test.cc b/src/bin/test_app/test_app_test.cc
index f796c17..b5e806f 100644
--- a/src/bin/test_app/test_app_test.cc
+++ b/src/bin/test_app/test_app_test.cc
@@ -69,13 +69,12 @@
private:
const ProjectContext* project_context_;
std::unique_ptr<FakeObservationStore> observation_store_;
- uint32_t last_obs_generation_;
+ uint32_t last_obs_generation_ = 0;
};
TestLoggerFactory::TestLoggerFactory(const ProjectContext* project_context)
: project_context_(project_context),
- observation_store_(new FakeObservationStore),
- last_obs_generation_(0) {}
+ observation_store_(new FakeObservationStore) {}
std::unique_ptr<LoggerInterface> TestLoggerFactory::NewLogger(uint32_t /*day_index*/) {
return nullptr;
diff --git a/src/lib/util/consistent_proto_store_test.cc b/src/lib/util/consistent_proto_store_test.cc
index a2e2bf8..529b582 100644
--- a/src/lib/util/consistent_proto_store_test.cc
+++ b/src/lib/util/consistent_proto_store_test.cc
@@ -31,11 +31,7 @@
class TestConsistentProtoStore : public ConsistentProtoStore {
public:
explicit TestConsistentProtoStore(const std::string &filename)
- : ConsistentProtoStore(filename, &fs_),
- fail_write_tmp_(false),
- fail_move_tmp_(false),
- fail_delete_primary_(false),
- fail_move_override_to_primary_(false) {}
+ : ConsistentProtoStore(filename, &fs_) {}
~TestConsistentProtoStore() override = default;
@@ -81,10 +77,10 @@
}
PosixFileSystem fs_;
- bool fail_write_tmp_;
- bool fail_move_tmp_;
- bool fail_delete_primary_;
- bool fail_move_override_to_primary_;
+ bool fail_write_tmp_ = false;
+ bool fail_move_tmp_ = false;
+ bool fail_delete_primary_ = false;
+ bool fail_move_override_to_primary_ = false;
};
class ConsistentProtoStoreTest : public ::testing::Test {
diff --git a/src/local_aggregation/event_aggregator_test.cc b/src/local_aggregation/event_aggregator_test.cc
index 418f1a4..0bd9f8b 100644
--- a/src/local_aggregation/event_aggregator_test.cc
+++ b/src/local_aggregation/event_aggregator_test.cc
@@ -44,7 +44,6 @@
using logger::testing::MakeAggregationConfig;
using logger::testing::MakeAggregationKey;
using logger::testing::TestUpdateRecipient;
-using system_data::ClientSecret;
using util::EncryptedMessageMaker;
using util::IncrementingSteadyClock;
using util::IncrementingSystemClock;
diff --git a/src/logger/internal_metrics.h b/src/logger/internal_metrics.h
index 3adcc34..4dfda4c 100644
--- a/src/logger/internal_metrics.h
+++ b/src/logger/internal_metrics.h
@@ -219,7 +219,7 @@
class InternalMetricsPauseWrapper : public InternalMetrics {
public:
explicit InternalMetricsPauseWrapper(InternalMetrics* internal_metrics)
- : wrapped_internal_metrics_(internal_metrics), paused_(false) {}
+ : wrapped_internal_metrics_(internal_metrics) {}
void LoggerCalled(PerProjectLoggerCallsMadeMetricDimensionLoggerMethod method,
const Project& project) override {
@@ -300,7 +300,7 @@
private:
InternalMetricsPtr wrapped_internal_metrics_;
- bool paused_;
+ bool paused_ = false;
};
} // namespace cobalt::logger
diff --git a/src/observation_store/file_observation_store.h b/src/observation_store/file_observation_store.h
index c4b9c75..4f60737 100644
--- a/src/observation_store/file_observation_store.h
+++ b/src/observation_store/file_observation_store.h
@@ -61,8 +61,7 @@
: fs_(fs),
store_(store),
root_directory_(std::move(root_directory)),
- file_names_({file_name}),
- envelope_read_(false) {
+ file_names_({file_name}) {
CHECK(store_);
}
@@ -85,7 +84,7 @@
// These files should all be read into |envelope| when GetEnvelope is
// called.
std::set<std::string> file_names_;
- bool envelope_read_;
+ bool envelope_read_ = false;
Envelope envelope_;
size_t cached_file_size_ = 0;
};
diff --git a/src/observation_store/memory_observation_store.cc b/src/observation_store/memory_observation_store.cc
index 4b428a2..6ff2cbb 100644
--- a/src/observation_store/memory_observation_store.cc
+++ b/src/observation_store/memory_observation_store.cc
@@ -25,8 +25,7 @@
: ObservationStore(max_bytes_per_observation, max_bytes_per_envelope, max_bytes_total),
envelope_send_threshold_size_(
std::lround(kSendThresholdPercent * static_cast<float>(max_bytes_per_envelope_))),
- current_envelope_(new EnvelopeMaker(max_bytes_per_observation, max_bytes_per_envelope)),
- finalized_envelopes_size_(0) {
+ current_envelope_(new EnvelopeMaker(max_bytes_per_observation, max_bytes_per_envelope)) {
ResetInternalMetrics(internal_metrics);
}
diff --git a/src/observation_store/memory_observation_store.h b/src/observation_store/memory_observation_store.h
index 7965f99..abeb920 100644
--- a/src/observation_store/memory_observation_store.h
+++ b/src/observation_store/memory_observation_store.h
@@ -53,7 +53,7 @@
mutable std::mutex envelope_mutex_;
std::unique_ptr<EnvelopeMaker> current_envelope_;
std::deque<std::unique_ptr<EnvelopeHolder>> finalized_envelopes_;
- size_t finalized_envelopes_size_;
+ size_t finalized_envelopes_size_ = 0;
logger::InternalMetricsPtr internal_metrics_;
};
diff --git a/tools/get_files.py b/tools/get_files.py
index 47b8aae..98b57de 100644
--- a/tools/get_files.py
+++ b/tools/get_files.py
@@ -29,6 +29,7 @@
os.path.join(SRC_ROOT_DIR, 'sysroot'),
os.path.join(SRC_ROOT_DIR, 'third_party'),
os.path.join(SRC_ROOT_DIR, 'build'),
+ os.path.join(SRC_ROOT_DIR, 'cmake-build-debug'),
os.path.join(SRC_ROOT_DIR, 'src', 'bin', 'config_parser', 'src',
'source_generator', 'source_generator_test_files'),
]