summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorimplicitfield <114500360+implicitfield@users.noreply.github.com>2022-11-19 18:30:55 +0200
committerAndreas Kling <kling@serenityos.org>2022-11-23 11:19:16 +0100
commitee0c9ed87b4a6977d30517947ea7ba2321d47c1e (patch)
treeb930d95076b65cf6a45265417efc0b76ff7779b4
parent0f1f92553213c6c2c7268078c9d39b813c24bb49 (diff)
downloadserenity-ee0c9ed87b4a6977d30517947ea7ba2321d47c1e.zip
LibArchive: Simplify error handling
-rw-r--r--Meta/Lagom/Fuzzers/FuzzTar.cpp3
-rw-r--r--Userland/Libraries/LibArchive/TarStream.cpp6
-rw-r--r--Userland/Libraries/LibArchive/TarStream.h6
-rw-r--r--Userland/Utilities/tar.cpp10
4 files changed, 5 insertions, 20 deletions
diff --git a/Meta/Lagom/Fuzzers/FuzzTar.cpp b/Meta/Lagom/Fuzzers/FuzzTar.cpp
index 45d4cd9a02..5e76197eae 100644
--- a/Meta/Lagom/Fuzzers/FuzzTar.cpp
+++ b/Meta/Lagom/Fuzzers/FuzzTar.cpp
@@ -34,8 +34,7 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
return 0;
}
- auto maybe_error = tar_stream.advance();
- if (maybe_error.is_error())
+ if (tar_stream.advance().is_error())
return 0;
}
diff --git a/Userland/Libraries/LibArchive/TarStream.cpp b/Userland/Libraries/LibArchive/TarStream.cpp
index d92ac1e374..9b81784ebb 100644
--- a/Userland/Libraries/LibArchive/TarStream.cpp
+++ b/Userland/Libraries/LibArchive/TarStream.cpp
@@ -104,11 +104,7 @@ ErrorOr<void> TarInputStream::advance()
m_generation++;
- auto header_size_or_error = m_header.size();
- if (header_size_or_error.is_error())
- return header_size_or_error.release_error();
- auto header_size = header_size_or_error.release_value();
-
+ auto header_size = TRY(m_header.size());
VERIFY(m_stream.discard_or_error(block_ceiling(header_size) - m_file_offset));
m_file_offset = 0;
diff --git a/Userland/Libraries/LibArchive/TarStream.h b/Userland/Libraries/LibArchive/TarStream.h
index 9f26208ae4..d871638313 100644
--- a/Userland/Libraries/LibArchive/TarStream.h
+++ b/Userland/Libraries/LibArchive/TarStream.h
@@ -75,11 +75,7 @@ inline ErrorOr<void> TarInputStream::for_each_extended_header(F func)
Archive::TarFileStream file_stream = file_contents();
- auto header_size_or_error = header().size();
- if (header_size_or_error.is_error())
- return header_size_or_error.release_error();
- auto header_size = header_size_or_error.release_value();
-
+ auto header_size = TRY(header().size());
ByteBuffer file_contents_buffer = TRY(ByteBuffer::create_zeroed(header_size));
VERIFY(file_stream.read(file_contents_buffer) == header_size);
diff --git a/Userland/Utilities/tar.cpp b/Userland/Utilities/tar.cpp
index 16c6852283..dca9a18947 100644
--- a/Userland/Utilities/tar.cpp
+++ b/Userland/Utilities/tar.cpp
@@ -159,11 +159,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
if (extract) {
String absolute_path = Core::File::absolute_path(filename);
auto parent_path = LexicalPath(absolute_path).parent();
-
- auto header_mode_or_error = header.mode();
- if (header_mode_or_error.is_error())
- return header_mode_or_error.release_error();
- auto header_mode = header_mode_or_error.release_value();
+ auto header_mode = TRY(header.mode());
switch (header.type_flag()) {
case Archive::TarFileType::NormalFile:
@@ -204,9 +200,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
// Non-global headers should be cleared after every file.
local_overrides.clear();
- auto maybe_error = tar_stream.advance();
- if (maybe_error.is_error())
- return maybe_error.error();
+ TRY(tar_stream.advance());
}
file_stream.close();