From 4994718d8df9a42cfc6c9d0908de07ad240e555c Mon Sep 17 00:00:00 2001 From: Kenneth Myhra Date: Mon, 28 Mar 2022 22:56:14 +0200 Subject: [PATCH] test-fuzz: Port to LibMain Also use StringView in place of raw C strings and String. --- Userland/Utilities/CMakeLists.txt | 2 +- Userland/Utilities/test-fuzz.cpp | 23 +++++++++-------------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt index 4404c021d2b..e24c852b90c 100644 --- a/Userland/Utilities/CMakeLists.txt +++ b/Userland/Utilities/CMakeLists.txt @@ -197,7 +197,7 @@ target_link_libraries(tar LibMain LibArchive LibCompress) target_link_libraries(tee LibMain) target_link_libraries(telws LibProtocol LibLine LibMain) target_link_libraries(test-bindtodevice LibMain) -target_link_libraries(test-fuzz LibCore LibGemini LibGfx LibHTTP LibIPC LibJS LibMarkdown LibShell) +target_link_libraries(test-fuzz LibCore LibGemini LibGfx LibHTTP LibIPC LibJS LibMarkdown LibShell LibMain) target_link_libraries(test-imap LibIMAP LibMain) target_link_libraries(test-pthread LibThreading) target_link_libraries(timezone LibMain) diff --git a/Userland/Utilities/test-fuzz.cpp b/Userland/Utilities/test-fuzz.cpp index 1ca6bb203bc..514f00361ad 100644 --- a/Userland/Utilities/test-fuzz.cpp +++ b/Userland/Utilities/test-fuzz.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #define ENUMERATE_TARGETS(T) \ @@ -112,9 +112,9 @@ ENUMERATE_TARGETS(__ENUMERATE_TARGET) #include #undef LLVMFuzzerTestOneInput -static auto parse_target_name(const String& name) +static auto parse_target_name(StringView name) { - if (name == "list") { + if (name == "list"sv) { outln("The following targets are included:"); #undef __ENUMERATE_TARGET #define __ENUMERATE_TARGET(x) outln(#x); @@ -134,25 +134,20 @@ static auto parse_target_name(const String& name) exit(1); } -int main(int argc, char** argv) +ErrorOr serenity_main(Main::Arguments arguments) { - const char* type; - const char* filename; + StringView type; + StringView filename; Core::ArgsParser args_parser; args_parser.add_positional_argument(type, "Type of fuzzing target to run (use \"list\" to list all existing)", "target-kind"); args_parser.add_positional_argument(filename, "Input file", "filename"); - args_parser.parse(argc, argv); + args_parser.parse(arguments); auto fn = parse_target_name(type); - auto file = Core::File::open(filename, Core::OpenMode::ReadOnly); - if (file.is_error()) { - warnln("Cannot read from file: {}", file.error()); - exit(1); - } - - auto input = file.value()->read_all(); + auto file = TRY(Core::File::open(filename, Core::OpenMode::ReadOnly)); + auto input = file->read_all(); return fn(input.data(), input.size()); }