summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew <andrewlassalle@chromium.org>2020-03-26 13:40:37 -0700
committerCommit Bot <commit-bot@chromium.org>2020-03-28 17:20:31 +0000
commit9d5a61d7c71beb655e67eaf5c685e7add8f7768d (patch)
tree153e89c077acd3d77b638c8fb89bc2a091daa911
parent48ec4c85c00fc7be778dd2d1ce37d8f2908f8f17 (diff)
update_engine: Fix issues reported by clang-tidy
Fix uninitialized variables and some other minor issues reported by clang-tidy. BUG=chromium:982837 TEST=cros_workon_make update_engine --test Change-Id: I305dedb058c9b0787ba2f68feff42afe6810a276 Reviewed-on: https://chromium-review.googlesource.com/c/aosp/platform/system/update_engine/+/2122683 Reviewed-by: Amin Hassani <ahassani@chromium.org> Tested-by: Andrew Lassalle <andrewlassalle@chromium.org> Commit-Queue: Andrew Lassalle <andrewlassalle@chromium.org>
-rw-r--r--common/hwid_override.cc2
-rw-r--r--common/subprocess.cc1
-rw-r--r--common_service.cc2
-rw-r--r--common_service.h3
-rw-r--r--dbus_service.cc1
-rw-r--r--omaha_request_action.cc1
-rw-r--r--omaha_request_params.cc2
-rw-r--r--p2p_manager.cc1
-rw-r--r--payload_consumer/delta_performer.cc2
-rw-r--r--payload_consumer/postinstall_runner_action.cc1
-rw-r--r--payload_generator/deflate_utils.cc2
-rw-r--r--payload_generator/delta_diff_utils.cc14
-rw-r--r--payload_generator/delta_diff_utils_unittest.cc2
-rw-r--r--payload_generator/extent_ranges.cc1
-rw-r--r--update_attempter.cc2
-rw-r--r--update_engine_client.cc2
-rw-r--r--update_manager/staging_utils.cc1
17 files changed, 19 insertions, 21 deletions
diff --git a/common/hwid_override.cc b/common/hwid_override.cc
index 8800e948..1bb0f8f5 100644
--- a/common/hwid_override.cc
+++ b/common/hwid_override.cc
@@ -16,14 +16,12 @@
#include "update_engine/common/hwid_override.h"
-#include <map>
#include <string>
#include <base/files/file_path.h>
#include <base/files/file_util.h>
#include <brillo/key_value_store.h>
-using std::map;
using std::string;
namespace chromeos_update_engine {
diff --git a/common/subprocess.cc b/common/subprocess.cc
index 52065030..24ad2d9b 100644
--- a/common/subprocess.cc
+++ b/common/subprocess.cc
@@ -36,7 +36,6 @@
#include "update_engine/common/utils.h"
-using brillo::MessageLoop;
using std::string;
using std::unique_ptr;
using std::vector;
diff --git a/common_service.cc b/common_service.cc
index b94e7340..347833b4 100644
--- a/common_service.cc
+++ b/common_service.cc
@@ -217,7 +217,7 @@ bool UpdateEngineService::GetChannel(ErrorPtr* /* error */,
}
bool UpdateEngineService::SetCohortHint(ErrorPtr* error,
- string in_cohort_hint) {
+ const string& in_cohort_hint) {
PrefsInterface* prefs = system_state_->prefs();
// It is ok to override the cohort hint with an invalid value since it is
diff --git a/common_service.h b/common_service.h
index a74c46bf..6c742a5d 100644
--- a/common_service.h
+++ b/common_service.h
@@ -109,7 +109,8 @@ class UpdateEngineService {
// Sets the current "cohort hint" value to |in_cohort_hint|. The cohort hint
// is sent back to Omaha on every request and can be used as a hint of what
// cohort should we be put on.
- bool SetCohortHint(brillo::ErrorPtr* error, std::string in_cohort_hint);
+ bool SetCohortHint(brillo::ErrorPtr* error,
+ const std::string& in_cohort_hint);
// Return the current cohort hint. This value can be set with SetCohortHint()
// and can also be updated from Omaha on every update check request.
diff --git a/dbus_service.cc b/dbus_service.cc
index cd714881..a5fec740 100644
--- a/dbus_service.cc
+++ b/dbus_service.cc
@@ -36,7 +36,6 @@ using std::vector;
using update_engine::Operation;
using update_engine::StatusResult;
using update_engine::UpdateEngineStatus;
-using update_engine::UpdateStatus;
namespace {
// Converts the internal |UpdateEngineStatus| to the protobuf |StatusResult|.
diff --git a/omaha_request_action.cc b/omaha_request_action.cc
index 8890c7c9..50fe3cc9 100644
--- a/omaha_request_action.cc
+++ b/omaha_request_action.cc
@@ -59,7 +59,6 @@ using base::Time;
using base::TimeDelta;
using chromeos_update_manager::kRollforwardInfinity;
using std::map;
-using std::numeric_limits;
using std::string;
using std::vector;
diff --git a/omaha_request_params.cc b/omaha_request_params.cc
index 1cfbc9c8..b6c18a6c 100644
--- a/omaha_request_params.cc
+++ b/omaha_request_params.cc
@@ -39,9 +39,7 @@
#define CALL_MEMBER_FN(object, member) ((object).*(member))
-using std::map;
using std::string;
-using std::vector;
namespace chromeos_update_engine {
diff --git a/p2p_manager.cc b/p2p_manager.cc
index 5de91d13..00ff8cec 100644
--- a/p2p_manager.cc
+++ b/p2p_manager.cc
@@ -65,7 +65,6 @@ using brillo::MessageLoop;
using chromeos_update_manager::EvalStatus;
using chromeos_update_manager::Policy;
using chromeos_update_manager::UpdateManager;
-using std::map;
using std::pair;
using std::string;
using std::unique_ptr;
diff --git a/payload_consumer/delta_performer.cc b/payload_consumer/delta_performer.cc
index 3263ff7d..11cf0069 100644
--- a/payload_consumer/delta_performer.cc
+++ b/payload_consumer/delta_performer.cc
@@ -533,7 +533,7 @@ MetadataParseResult DeltaPerformer::ParsePayloadMetadata(
#define OP_DURATION_HISTOGRAM(_op_name, _start_time) \
LOCAL_HISTOGRAM_CUSTOM_TIMES( \
"UpdateEngine.DownloadAction.InstallOperation::" _op_name ".Duration", \
- base::TimeTicks::Now() - _start_time, \
+ (base::TimeTicks::Now() - _start_time), \
base::TimeDelta::FromMilliseconds(10), \
base::TimeDelta::FromMinutes(5), \
20);
diff --git a/payload_consumer/postinstall_runner_action.cc b/payload_consumer/postinstall_runner_action.cc
index 264161ca..9ecda488 100644
--- a/payload_consumer/postinstall_runner_action.cc
+++ b/payload_consumer/postinstall_runner_action.cc
@@ -49,7 +49,6 @@ const int kPostinstallStatusFd = 3;
namespace chromeos_update_engine {
-using brillo::MessageLoop;
using std::string;
using std::vector;
diff --git a/payload_generator/deflate_utils.cc b/payload_generator/deflate_utils.cc
index 8db67ce0..5d7a766a 100644
--- a/payload_generator/deflate_utils.cc
+++ b/payload_generator/deflate_utils.cc
@@ -46,7 +46,7 @@ const uint64_t kMinimumSquashfsImageSize = 1 * 1024 * 1024; // bytes
// TODO(*): Optimize this so we don't have to read all extents into memory in
// case it is large.
bool CopyExtentsToFile(const string& in_path,
- const vector<Extent> extents,
+ const vector<Extent>& extents,
const string& out_path,
size_t block_size) {
brillo::Blob data(utils::BlocksInExtents(extents) * block_size);
diff --git a/payload_generator/delta_diff_utils.cc b/payload_generator/delta_diff_utils.cc
index db69d740..53a3cf17 100644
--- a/payload_generator/delta_diff_utils.cc
+++ b/payload_generator/delta_diff_utils.cc
@@ -250,12 +250,13 @@ FilesystemInterface::File GetOldFile(
if (old_file_iter != old_files_map.end())
return old_file_iter->second;
- // No old file match for the new file name, use a similar file with the
- // shortest levenshtein distance.
+ // No old file matches the new file name. Use a similar file with the
+ // shortest levenshtein distance instead.
// This works great if the file has version number in it, but even for
// a completely new file, using a similar file can still help.
- int min_distance = new_file_name.size();
- const FilesystemInterface::File* old_file;
+ int min_distance =
+ LevenshteinDistance(new_file_name, old_files_map.begin()->first);
+ const FilesystemInterface::File* old_file = &old_files_map.begin()->second;
for (const auto& pair : old_files_map) {
int distance = LevenshteinDistance(new_file_name, pair.first);
if (distance < min_distance) {
@@ -580,6 +581,11 @@ bool DeltaReadFile(vector<AnnotatedOperation>* aops,
InstallOperation operation;
uint64_t total_blocks = utils::BlocksInExtents(new_extents);
+ if (chunk_blocks == 0) {
+ LOG(ERROR) << "Invalid number of chunk_blocks. Cannot be 0.";
+ return false;
+ }
+
if (chunk_blocks == -1)
chunk_blocks = total_blocks;
diff --git a/payload_generator/delta_diff_utils_unittest.cc b/payload_generator/delta_diff_utils_unittest.cc
index bc3dca57..8a97b1bf 100644
--- a/payload_generator/delta_diff_utils_unittest.cc
+++ b/payload_generator/delta_diff_utils_unittest.cc
@@ -595,6 +595,8 @@ TEST_F(DeltaDiffUtilsTest, GetOldFileTest) {
"update_engine");
EXPECT_EQ(diff_utils::GetOldFile(old_files_map, "bin/delta_generator").name,
"delta_generator");
+ // Check file name with minimum size.
+ EXPECT_EQ(diff_utils::GetOldFile(old_files_map, "a").name, "filename");
}
} // namespace chromeos_update_engine
diff --git a/payload_generator/extent_ranges.cc b/payload_generator/extent_ranges.cc
index 0e3f087e..4600efe7 100644
--- a/payload_generator/extent_ranges.cc
+++ b/payload_generator/extent_ranges.cc
@@ -27,7 +27,6 @@
#include "update_engine/payload_consumer/payload_constants.h"
#include "update_engine/payload_generator/extent_utils.h"
-using std::set;
using std::vector;
namespace chromeos_update_engine {
diff --git a/update_attempter.cc b/update_attempter.cc
index f5885c91..29d256cb 100644
--- a/update_attempter.cc
+++ b/update_attempter.cc
@@ -742,7 +742,7 @@ void UpdateAttempter::CalculateDlcParams() {
}
}
std::map<std::string, OmahaRequestParams::AppParams> dlc_apps_params;
- for (auto dlc_id : dlc_module_ids_) {
+ for (const auto& dlc_id : dlc_module_ids_) {
OmahaRequestParams::AppParams dlc_params{
.active_counting_type = OmahaRequestParams::kDateBased,
.name = dlc_id,
diff --git a/update_engine_client.cc b/update_engine_client.cc
index eb718410..a721f7a7 100644
--- a/update_engine_client.cc
+++ b/update_engine_client.cc
@@ -202,7 +202,7 @@ class UpdateWaitHandler : public ExitingStatusUpdateHandler {
void UpdateWaitHandler::HandleStatusUpdate(const UpdateEngineStatus& status) {
if (exit_on_error_ && status.status == UpdateStatus::IDLE) {
- int last_attempt_error;
+ int last_attempt_error = static_cast<int>(ErrorCode::kSuccess);
ErrorCode code = ErrorCode::kSuccess;
if (client_ && client_->GetLastAttemptError(&last_attempt_error))
code = static_cast<ErrorCode>(last_attempt_error);
diff --git a/update_manager/staging_utils.cc b/update_manager/staging_utils.cc
index 4835ab22..f4f685c6 100644
--- a/update_manager/staging_utils.cc
+++ b/update_manager/staging_utils.cc
@@ -32,7 +32,6 @@
using base::TimeDelta;
using chromeos_update_engine::kPrefsWallClockStagingWaitPeriod;
using chromeos_update_engine::PrefsInterface;
-using chromeos_update_engine::SystemState;
using policy::DevicePolicy;
namespace chromeos_update_manager {