From bda181a86a89ebcd3d6eb1208d173bec05316e11 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 7 Feb 2023 05:22:22 +0000 Subject: [PATCH] libsnapshot: Fix crash in cow writer test due to missing ASSERT. Bug: N/A Test: vts_libsnapshot_test Change-Id: I72cf6f52fc15061da669d14cf5d334b44ad83501 --- fs_mgr/libsnapshot/libsnapshot_cow/cow_writer.cpp | 9 ++++----- fs_mgr/libsnapshot/snapshot_writer_test.cpp | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/fs_mgr/libsnapshot/libsnapshot_cow/cow_writer.cpp b/fs_mgr/libsnapshot/libsnapshot_cow/cow_writer.cpp index 3932fad94..56b48f0c7 100644 --- a/fs_mgr/libsnapshot/libsnapshot_cow/cow_writer.cpp +++ b/fs_mgr/libsnapshot/libsnapshot_cow/cow_writer.cpp @@ -298,13 +298,12 @@ bool CowWriter::Initialize(borrowed_fd fd) { return false; } - bool ret = OpenForWrite(); - - if (ret) { - InitWorkers(); + if (!OpenForWrite()) { + return false; } - return ret; + InitWorkers(); + return true; } bool CowWriter::InitializeAppend(android::base::unique_fd&& fd, uint64_t label) { diff --git a/fs_mgr/libsnapshot/snapshot_writer_test.cpp b/fs_mgr/libsnapshot/snapshot_writer_test.cpp index da48eb933..a03632b46 100644 --- a/fs_mgr/libsnapshot/snapshot_writer_test.cpp +++ b/fs_mgr/libsnapshot/snapshot_writer_test.cpp @@ -33,8 +33,8 @@ TEST_F(CompressedSnapshotWriterTest, ReadAfterWrite) { TemporaryFile cow_device_file{}; android::snapshot::CowOptions options{.block_size = BLOCK_SIZE}; android::snapshot::CompressedSnapshotWriter snapshot_writer{options}; - snapshot_writer.SetCowDevice(android::base::unique_fd{cow_device_file.fd}); - snapshot_writer.Initialize(); + ASSERT_TRUE(snapshot_writer.SetCowDevice(android::base::unique_fd{cow_device_file.fd})); + ASSERT_TRUE(snapshot_writer.Initialize()); std::vector buffer; buffer.resize(BLOCK_SIZE); std::fill(buffer.begin(), buffer.end(), 123);