summaryrefslogtreecommitdiff
path: root/payload_generator/delta_diff_utils.cc
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 /payload_generator/delta_diff_utils.cc
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>
Diffstat (limited to 'payload_generator/delta_diff_utils.cc')
-rw-r--r--payload_generator/delta_diff_utils.cc14
1 files changed, 10 insertions, 4 deletions
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;