From a263a88381a3fad800dbdfc8792c89b4c94b8a21 Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Fri, 19 Feb 2021 13:01:33 -0800 Subject: [PATCH] snapuserd: fix a use of an uninitialized value `header` is only initialized in the `if` block of this condition. Hence, its use in the `else` portion isn't correct. Refactor the code a bit to make this kind of bug a bit harder to write in the future. Caught by the static analyzer: > system/core/fs_mgr/libsnapshot/snapuserd.cpp:457:9: warning: 1st function call argument is an uninitialized value [clang-analyzer-core.CallAndMessage] Bug: None Test: TreeHugger Change-Id: Ie56578520acf3cc972efa3336e40698feed20200 --- fs_mgr/libsnapshot/snapuserd.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/fs_mgr/libsnapshot/snapuserd.cpp b/fs_mgr/libsnapshot/snapuserd.cpp index d62030050..4c4a34225 100644 --- a/fs_mgr/libsnapshot/snapuserd.cpp +++ b/fs_mgr/libsnapshot/snapuserd.cpp @@ -447,16 +447,15 @@ chunk_t Snapuserd::GetNextAllocatableChunkId(chunk_t chunk) { } void Snapuserd::CheckMergeCompletionStatus() { - CowHeader header; - - if (merge_initiated_) { - reader_->GetHeader(&header); - SNAP_LOG(INFO) << "Merge-status: Total-Merged-ops: " << header.num_merge_ops - << " Total-data-ops: " << reader_->total_data_ops(); - } else { - SNAP_LOG(INFO) << "Merge was not initiated. Total-Merged-ops: " << header.num_merge_ops - << " Total-data-ops: " << reader_->total_data_ops(); + if (!merge_initiated_) { + SNAP_LOG(INFO) << "Merge was not initiated. Total-data-ops: " << reader_->total_data_ops(); + return; } + + CowHeader header; + reader_->GetHeader(&header); + SNAP_LOG(INFO) << "Merge-status: Total-Merged-ops: " << header.num_merge_ops + << " Total-data-ops: " << reader_->total_data_ops(); } /*